Show lines that do not contain specific linux lines

I have a text file in 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 that do not contain "PUM-DT_MAX_1234", and save in another file with the identifier

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 does not work

any suggestions

thank!

+5
source share
5 answers
sed '1b
h;s/.*DRogan^D//;s/PUM-DT_MAX_1234;\{0,1\}//g;s/;$//;/./!d
H;g;s/,.*\n/,/' YourFile
  • based on your sample

Concept: - save a copy of the line - remove the head and any PUM from the line, check if there is anything left - return the header (from the buffered line) and reformat the cut line

+1
source

use awk '$0 !~ /your_pattern/'

as found in the (possibly) largest awk doc

+17
source

, , "PUM-DT_MAX_1234", :

awk -F "[;,]" -v OFS="," 'NR==1 { next; }; { for (i=1;i<=NF;i++) { if(!match($i,/.*PUM-DT_MAX_1234.*/) && length($i) > 0) { if (i==1) r=$i;  else r = r OFS $i }}; print r }' filter.txt

:

  • -F "[;,]" ; ,
  • -v OFS="," ,
  • 'NR==1 { next; }; ' awk script, - ( 1,
  • { for (i=1;i<=NF;i++) { (NF)
  • if(!match($i,/.*PUM-DT_MAX_1234.*/) && length($i) > 0) {
  • if (i==1) r=$i; else r = r OFS $i ( , , )
  • print r }' , awk script '
  • filter.txt - .

OFS O utput F ield S, , .

:

MF00034657,M-DT_MAX_1
MF00056578,UM-DT_MAX_123
+2

ls ( ), , , mp4, :

ls | awk '! /\.mp4/'

, , mp4, , abc:

ls | awk '! /\.mp4/ &&  /abc/'

(, , ).

+1

In the @silgon answer above, the command worked after I removed the space in '! /. Mp4 /'

  • I wanted to remove the 'none' images from the output of 'docker images' using awk:

docker images | awk '!/\<none>/' 
Run codeHide result

  • I wanted to print the name and tag only from the output of 'docker images', i.e. columns 1 and 2 from the output, except for the "none" images using awk:

docker images | awk '!/\<none>/' | awk '{print $1,$2}'
Run codeHide result

0
source

All Articles