aspose file tools*
The moose likes Linux / UNIX and the fly likes How do I parse a numeric string with awk? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "How do I parse a numeric string with awk?" Watch "How do I parse a numeric string with awk?" New topic
Author

How do I parse a numeric string with awk?

Earl Frederick
Greenhorn

Joined: Feb 08, 2012
Posts: 1
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

Joined: Jun 25, 2001
Posts: 16250
    
  21

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How do I parse a numeric string with awk?