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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using grep to search in a field

Status
Not open for further replies.

jalge2

Technical User
Feb 5, 2003
105
US
I have a file. The file contains different information all separated by a comma. In the 8th field it either says prt8 or prt9. I want to grep for the 8 or the 9 in the 8th field. How do I do this?
 
You could use awk

awk -F, '$8 ~ /prt8/' file-name
awk -F, '$8 ~ /prt9/' file-name
awk -F, '$8 ~ /prt[89]/' file-name


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
to output all records with the eight field containing '9':
nawk -F, -v f="8" -v v="9" '$f ~ v' myFile.txt

vlad
+----------------------------+
| #include<disclaimer.h> |
+----------------------------+
 
Awk is your friend :
Try this (untested)

awk -F&quot;,&quot; '$8==&quot;prt9&quot;||$8==&quot;prt8&quot; {print}' yourfile

HTH


Dickie Bird (:)-)))
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top