Editing the timestamp

i have data in 3 columns in the format below

2011-11-01-0936,2115,978
2011-11-01-0937,2242,1046
2011-11-01-0938,2538,1186
2011-11-01-0939,2295,1074
2011-11-01-0940,2454,1142
2011-11-01-0941,2545,1184
2011-11-01-0942,2491,1153

I however want to either remove the date on the timestamp and remain with the time as below

0936,2115,978
0937,2242,1046
0938,2538,1186

Or convert the timestamp such that it represents the number of seconds into the day such that if the time is 0:00 its 0seconds and 8:30 is represented as 30600, 12:00 as 43200 and so on

To remove the date...

sed 's/.*[-^-]//g' input_file

To convert to seconds

awk -F"-|," 'gsub($4,substr($4,0,2)*60*60+substr($4,3)*60)' input_file

--ahamed

1 Like

Thanks. It worked like a charm to produce the output as below:
>

tail -f Attempts | sed 's/.*[-^-]//g'

1454,1934,881
1455,1936,886
1456,1843,842

where the first column is the time.

However on testing i still need to convert the time (first column of the data) such that it represents the number of seconds into the day such that if the time is 0000 its 0seconds and 0830 is represented as 30600, 1200 as 43200 and so on

>

tail -f Attempts | awk -F"-|," 'gsub($4,substr($4,0,2)*60*60+substr($4,3)*60)'

awk: syntax error near line 1
awk: bailing out near line 1

Where am i getting it wrong on the conversion to seconds?