Reputation: 3
I am using Sun OS 5.10 and Using nawk to extract field from csv file. The first column of csv is the time in Milliseconds and I need to convert it to Date then save it in another csv file.
Here is the command that handle this task
nawk 'BEGIN {FS = ","}; NR>1 split($42,a,"|") {print $1 "," $46 "," $48 ","
$47 "," null "," null "," a[2] "," $6 "," $49 "," $7 "," $8 ","}' ttt.csv >
tttn.csv
How can I handle this task?
Upvotes: 0
Views: 324
Reputation: 207808
Those are not milliseconds - they are seconds since the epoch on 1st Jan 1970.
Does this help? I change the value of the first field ($1
) then print the line with the modified field:
awk '{$1=strftime("%m/%d/%Y, %r",int($1))}1' YourFile
03/26/2018, 07:04:47 pm field2 field3
where YourFile
contains:
1522087487.9876 field2 field3
If you want rounding to the nearest second, you may want:
int($1+0.5)
in the strftime()
function.
If your nawk
doesn't have strftime()
, and none of the other awk
s on Solaris work, e.g. /usr/xpg4/awk
etc, then we may have to come up with a Perl solution - just say!
Upvotes: 0