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

checking # of digits in feild and adding zeros

Status
Not open for further replies.

jkluesner

Technical User
Sep 29, 2006
24
0
0
US
Hello all,

I am trying to edit some ship gps data and I am having a problem with getting the hour/minute gmt time in the format I need. This is how far I have been able to get the data:

02 05 2008 13 59 22.53617615 -106.69877400
02 05 2008 13 59 22.53617619 -106.69877400
02 05 2008 13 59 22.53617635 -106.69877420
02 05 2008 13 59 22.53617636 -106.69877420
02 05 2008 14 0 22.53617627 -106.69877430
02 05 2008 14 0 22.53617627 -106.69877430
02 05 2008 14 0 22.53617625 -106.69877430
02 05 2008 14 0 22.53617617 -106.69877440
02 05 2008 14 0 22.53617617 -106.69877440
02 05 2008 14 0 22.53617619 -106.69877440
02 05 2008 14 0 22.53617618 -106.69877450

the data is (Day, Month, Year, Hour, Minute, lat/long)

As you can see there is a step when the hour or minute drops down to one digit. This is a problem for me because I need the data to look like this.

05 09 2006 0508 27 04.0060-111 33.4300
05 09 2006 0509 27 03.9650-111 33.3480
05 09 2006 0510 27 03.9090-111 33.2520
05 09 2006 0511 27 03.8520-111 33.1350
05 09 2006 0512 27 03.8040-111 33.0350
05 09 2006 0513 27 03.7500-111 32.9380
05 09 2006 0514 27 03.6980-111 32.8400
05 09 2006 0515 27 03.6510-111 32.7370
05 09 2006 0516 27 03.6090-111 32.6570
05 09 2006 0517 27 03.5550-111 32.5590
05 09 2006 0518 27 03.4950-111 32.4430

Hour and minute have been combined into one field and there are zeros filled in to keep the field from changing digit size.

Anybody have any suggestions?

Thanks,

Jared
 
This code snippet calculates a time variable from fields 4 and 5 in the input file and prints that time in a 4char zero-filled field to the output.

[tt]awk '{time=(100*$4)+$5; printf "%04d\n", time}' /path/to/your/file[/tt]

Add the rest of the placeholders (e.g. %s) in the format string and the field numbers you want before and after the time in the output and you're there.


HTH,

p5wizard
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top