ubuntu - How to find different strings on the same line using grep -


I am trying to find all the rows within a text file that contain the first string, like some | Kittens Color | . And then I searched for || to leave in the next set of . Like to place want to leave the search for another string.

All the files in the pipe | In other words, I want all the lines in the text file that includes kittens, colors and places when they are in the file:

  12321415 | Kittens Color | Gender | Location |  

I think the best awk this way To use:

  awk -F "|" '$ 2 == "Kittens" & amp; Amp; $ 3 == "Color" & amp; Amp; $ 5 == "location" 'file  

this pipe | as a field separator, and depending on it, checks the values ​​of specific areas 2, 3 and 5. If they all match the given values, the line is printed.

Test

  $ cat a 12321415 | Kittens Color | Gender | Location | 12321415 | Kittens Color | Location | Blabla | Asdf | Asdf | Asdf | Advertising | Asd |  

and execute awk:

  $ awk -F "|" '$ 2 == "Kittens" & amp; Amp; $ 3 == "Color" & amp; Amp; $ 5 == "place" 'a 12321415 | Kittens Color | Gender | Location |  

Comments