Skip to content

Remove Specific Line in Configuration Files  #1

@PeterTeng

Description

@PeterTeng

It is possible to use sed command to remove specific line which match desired pattern

https://www.gnu.org/software/sed/manual/sed.html

sed Command Usage

$ cat a.txt
ip:111.111.111.111 text text text
ip:222.222.222.222 text text text
ip:333.333.333.333 text text text
ip:444.444.444.444 text text text

# Remove the line in file and print file with STDOUT
$ sed '/222.222.222.222/d' a.txt
ip:111.111.111.111 text text text
ip:333.333.333.333 text text text
ip:444.444.444.444 text text text

# Remove the line in file and modify the file
# In macOS --> sed -i '' '/222.222.222.222/d' a.txt 
$ sed -i '/222.222.222.222/d' a.txt 
$ cat a.txt
ip:111.111.111.111 text text text
ip:333.333.333.333 text text text
ip:444.444.444.444 text text text

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions