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

 You can remove entire lines in a text file that match a specific pattern using `grep` with the `-v` option to exclude matching lines. Here's an example using `grep` to remove lines containing a specific pattern from a text file:


```bash

grep -v "pattern" input.txt > output.txt

```


Replace `"pattern"` with the specific pattern you want to match, `input.txt` with the name of your input file, and `output.txt` with the name of the file where you want to save the result.


For example, if you want to remove lines containing the word "example" from a file called `data.txt` and save the result to a new file called `filtered_data.txt`, you can use the following command:


```bash

grep -v "example" data.txt > filtered_data.txt

```


This will create a new file `filtered_data.txt` that contains all the lines from `data.txt` except the ones containing the word "example."

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?