awk: delete the lines with the same first field after a match -


(updated example , solution) data grouped sequentially first fields. numbers of lines each first field variable. after match (of unfavored keywords) found, lines same first field match need deleted.

input is:

1  orange  dog    red 1  apple   cat    green 2  peach   frog   grey 3  apple  lamb   white 3  orange  lamb   white 3  mango   cat    yellow 3  apple   mouse  blue 

if match of either "cat" or "orange", lines same first fields ("1" or "3") deleted. output be:

2  peach   frog   grey 

the solution costas:

awk 'nr==fnr{if($0~/cat|orange/)l[$1]=1;next} !($1 in l)' test1.txt test1.txt 

awk ' # pass input 1 time find occurence of "cat" nr==fnr{     if( $0~/cat/)         l[$1]=1 # add founded 1st field array l     next        } # second pass print line if value of 1st field not in array l !($1 in l)' input input  

Comments

Popular posts from this blog

asp.net mvc - SSO between MVCForum and Umbraco7 -

Python Tkinter keyboard using bind -

ubuntu - Selenium Node Not Connecting to Hub, Not Opening Port -