How to remove entire string that match specific pattern in unix txt file with a single command line

 To remove entire lines in a text file that match a specific pattern using a single command line in Unix, you can use the `grep` command in combination with the `-v` option (which excludes lines that match the pattern) and the `-F` option (which treats the pattern as a fixed string, not a regular expression). Here's the command:


```bash

grep -v -F 'pattern' input.txt > output.txt

```


- Replace `'pattern'` with the specific pattern you want to match and remove.

- `input.txt` is the name of the input file.

- `output.txt` is the name of the output file where the lines without the matching pattern will be saved. You can use the same file name to overwrite the input file, or specify a different output file if you want to keep a backup.


For example, if you want to remove all lines in the file `input.txt` that contain the string "example," you can use the following command:


```bash

grep -v -F 'example' input.txt > output.txt

```


This will create a new file `output.txt` with all lines that match the pattern "example" removed. You can then review or use the `output.txt` file as needed.

Comments

Popular posts from this blog

bad character U+002D '-' in my helm template

GitLab pipeline stopped working with invalid yaml error

How do I add a printer in OpenSUSE which is being shared by a CUPS print server?