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

Searching in fixed locations with AWK...

Status
Not open for further replies.

bondtrails

Technical User
Nov 19, 2002
31
US
Hi all,
how can I match using fixed locations. It seems like AWK allows pattern matching, but I need to match in a fixed position. Ex:
FileA.txt contains:
aaaaJobCode bbbbb
aaaaJobControlbbbbb
aaaaJobStatus ccccc
eeeeJob dddddd

If I want only those records that match "Job " in locations 5-13, using awk '/Job /' FileA.txt won't work.

How to do?? I need to search by fixed location!!

--Bondster!!
 
Maybe

'/^....Jobs /'


CaKiwi

"I love mankind, it's people I can't stand" - Linus Van Pelt
 
I believe CaKiwi got an extra "s" in, so it should actually read:
[tt]
'/^....Job /'
[/tt]

I really wonder, why your example does not work for you, because it does for me ... your pattern matches exactly the desired line in your example ... that is really odd.

have a look at relative expressions in general.
 
Okay, thanks CaKiwi and Baraka, I got it to work :)
However, in the general sense, my question still lingers. If I wanted to search records of a file, but limiting my search within specific column locations, how would I do it. I am thinking perhaps the function "substr" might do it. Would the following work?
awk 'substr($0,start, length) ~ /REGEXP/ {print $0}'

Or is there a more efficient way to go about it?

--Bondster!!
P.S. THis is an awesome forum!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top