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!

I need to check for certain pattern 1

Status
Not open for further replies.

scottpeter

Programmer
Sep 23, 2003
28
US
I need to check for certain patterns in a particular column and display the records with that pattern.
I am using the command as follows. 231 to 242 is the coulmn position.

cut -c231-242 p1.dat | grep '100000000000'
cut -c231-242 p1.dat | grep '111111100000'
cut -c231-242 p1.dat | grep '111000000000'

But it pulls out only the column. How can I display the whole record with the matching pattern.

Thanks,
SP




 
awk is your friend:
Code:
awk '{tst=substr($0,231,12)
  if(tst=="100000000000" || tst=="111111100000" || tst=="111000000000")
    print
}' p1.dat


Hope This Help
PH.
 
Try

awk '/^.{230}(100000000000|111111100000|111000000000)' p1.dat


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
I left out the trailing /. I should be

awk '/^.{230}(100000000000|111111100000|111000000000)[red]/[/red]' p1.dat

The {n} works in very few versions of awk. The only one available to me that it worked in is MKS awk on the PC. It should work in the latest version of gawk, according to the documentation. An alternative solution is

awk 'substr($0,231,12) ~ /100000000000|111111100000|111000000000)/'p1.dat


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top