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

awk help

Status
Not open for further replies.

dwcasey

MIS
Oct 31, 2002
179
US
Before we upgraded our DB software, when we ran something like awk '{print $1,$2,$15}', the results were consistent.

Since upgrading, the last column can begin in position 15, 16 or 17.

Is there a way with awk to say go to eno-of-line and count back 5 characters?

I tried cut, but my delimter is a space " " and that doesn't help since spacing is irregular.

And I usually use sed to clean up data and I need to be able to assign $1, $2, and $15 to variables, so that is why we chose awk.

A sample line might look like:

ABC IXYZ123456 264525 2815 0 3 29 0 264525 28 87 3 0 0 *----

We get DB Name from $1, Tablename from $2 and $15 is the status. Certain character in certain places mean different things.

Sometimes it shifts a bit depending on the mix of the data.
 
Is there a way with awk to say go to end-of-line and count back 5 characters?
last5=substr($NF,length($NF)-4)

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ222-2244
 
Just as an aside, you can also regularise your spacing using tr -s ' ' ' ' before you do the cut, converting all spaces into one space.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top