I have a text file on my Linux server with these characters:
ID DATA
MF00034657,12435464^DRogan^DPUM-DT_MAX_1234;PUM-DT_MAX_1234;PUM-DT_MAX_1234;PUM-DT_MAX_1234;PUM-DT_MAX_1234;M-DT_MAX_1;
MF00056578,12435464^DRogan^DPUM-DT_MAX_1234;PUM-DT_MAX_1234;PUM-DT_MAX_1234;PUM-DT_MAX_1234;PUM-DT_MAX_1234;UM-DT_MAX_123;
Now I need to filter the lines which do not contain "PUM-DT_MAX_1234" and save them in another file with the ID.
Like this:
MF00034657,M-DT_MAX_1
MF00056578,UM-DT_MAX_123
I use:
grep -v 'PUM-DT_MAX_1234' file > file.out
awk '!/PUM-DT_MAX_1234/' file > file.out
But it doesn’t work.
How can I fix it?
When searching for certain file types that does not contain certain text or strings, you can use this command: >> find /home/example -iname "*. txt" -exec grep -Li "mystring" {} \+ This will list all text files that do NOT contain the term "mystring".
You want to use the "-L" option of grep : -L, --files-without-match Only the names of files not containing selected lines are written to standard output. Path- names are listed once per file searched.
Use the grep command to search the specified file for the pattern specified by the Pattern parameter and writes each matching line to standard output. This displays all lines in the pgm. s file that begin with a letter.
To check if a string contains a substring in Bash, use comparison operator == with the substring surrounded by * wildcards.
Use:
awk '$0 !~ /your_pattern/'
As found in the (probably) greatest AWK documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With