Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Search for a string in single field for all lines in file

Status
Not open for further replies.

TheDash

MIS
Mar 25, 2004
171
0
0
US
Hi all,
I would like to print all lines in a file based on conditions on nth field.

Example below: Here I would like to print all lines in which 6th field has (cat or dog or bat or rat)
and does not have (mat or pat).


File:

abc def ghi jkl mno cat_dog_bat_rat
abc def ghi jkl mno cat_dog_bat
abc def ghi jkl mno cat_dog
abc def ghi jkl mno cat
abc def ghi jkl mno cat_dog_bat_rat_mat_pat
abc def ghi jkl mno cat_dog_bat_rat_mat
abc def ghi jkl mno cat_dog_bat_rat_pat
abc def ghi jkl mno cat_dog_bat_rat_vat


Output should be:


abc def ghi jkl mno cat_dog_bat_rat
abc def ghi jkl mno cat_dog_bat
abc def ghi jkl mno cat_dog
abc def ghi jkl mno cat
abc def ghi jkl mno cat_dog_bat_rat_vat


Appreciate is someone can help with grep or sed script for this.

Thanks!
 
awk would be more suitable... give it a try and let us know if you get stuck?

Annihilannic
[small]tgmlify - code syntax highlighting for your tek-tips posts[/small]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top