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!

Reformatting a Line 1

Status
Not open for further replies.

tbohon

Programmer
Apr 20, 2000
293
US
I have a file containing lines in the following format:

/u/dir1/test/error05022006: 2322 = Total Error count...

(Note the multiple spaces between the colon and the value - I think that's where my problem lies. Also, the directory path - /u/dir1/test - will change from line to line so the lengths are always different.)

Anyway, I'm trying to grab values and produce a line like the following:

Total Errors for 20060502: 2322

(Note that the value can range from zero (0) to 5 or 6 digits.)

I'm sure awk can do it and started out by parsing on spaces. However, the multiple spaces are (I think) throwing me off and everything gets worse from there.

Any suggestions/ideas/thought/comments/blank checks greatly appreciated! :)

And thanks as always in advance for the assistance.

Tom

"My mind is like a steel whatchamacallit ...
 
How about this:

[tt] awk '{
y=substr($1,length($1)-4,4)
d=substr($1,length($1)-8,4)
print "Total Errors for " y d ": " $2
}' filename[/tt]

Annihilannic.
 
Annihilannic:

Works like a charm!!! I was all wrapped around the axle and not using substr ... why I didn't think about it is beyond me other than too many hours in front of a computer recently.

Thanks a bunch!

Best,

Tom

"My mind is like a steel whatchamacallit ...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top