This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How do I parse a numeric string with awk?

 
Earl Frederick
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a string in a data file 120134752 i'd like to separate this string into 3 pieces HHMMSSSSS and print that into
a new file as 3 separated strings as HH MM SSSSS (using a space as separator. I can't find any tips in books or online).

the full record in the file looks like this 3828100291 67037746 309500213 100950 120134752

thanks for any help!

earlb
 
Tim Holloway
Saloon Keeper
Pie
Posts: 18277
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Ranch, Earl!

I'm out of practice, but awk is based on regex processing, so the easiest way to break a string like HHMMSSSS into components would be to use groupings, like so:
[code]
(\d\d)(\d\d)(\dddd)
[code]

Which would then be mapped to individual variables ($1, $2, $3). Actually, I think that you can map them to named variables, but like I said, I'm really out of practice with AWK.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic