regex - HOW TO EXTRACT LIST 1 FROM LIST2 in Bash/Unix? -


i have 2 list. need extract rows have first list row elements second list. looking right syntax read 1 list , other , extract list 1 2 based on regex. looking exact text match. output include whole row list2 well. thanks.

list 1 in text file:

abc efg hij klm 

list 2 in text file:

tttt;kkkkkkk;ooooo;efg dalfjkhd;hij;ppp gsfdhgjh;fhajdjfkasljk;abc;asdkfhjaskabc;fa;lkdja abc;hhhhh;llll dddd;lllll ppppppppp:rrrrrrrrrradjkfjadl;fireuqwoepiruqwepiormvndfkgjs; hflahflakjdfhalksdfhfjaoeirfjaklf;sdfgsfgs 

desired output..the text in list 1 found ..space , row found in list 2.:

efg tttt;kkkkkkk;ooooo;efg hij dalfjkhd;hij;ppp abc gsfdhgjh;fhajdjfkasljk;abc;asdkfhjaskabc;fa;lkdja abc abc;hhhhh;llll 

try grep -f

grep -f list1 list2 

man grep

-f file, --file=file

read 1 or more newline separated patterns file. empty pattern lines match every input line. newlines not considered part of pattern. if file empty, nothing matched.


edit: example of grep -f in action

$ cat list1 abc efg hij klm  $ cat list2 tttt;kkkkkkk;ooooo;efg dalfjkhd;hij;ppp gsfdhgjh;fhajdjfkasljk;abc;asdkfhjaskabc;fa;lkdja abc;hhhhh;llll dddd;lllll ppppppppp:rrrrrrrrrradjkfjadl;fireuqwoepiruqwepiormvndfkgjs; hflahflakjdfhalksdfhfjaoeirfjaklf;sdfgsfgs  $ grep -f list1 list2 tttt;kkkkkkk;ooooo;efg dalfjkhd;hij;ppp gsfdhgjh;fhajdjfkasljk;abc;asdkfhjaskabc;fa;lkdja abc;hhhhh;llll 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -