How can I convert this timestamp into seconds?
I have a file xyz.txt
containing the following inform开发者_如何学Goation:
19-10-13-404566 1-3039 1 xyz
19-10-14-890768 1-3039 2 zxv
..........................
I want the first column of the file converted into 19*3600 + 10*60 + 13
(68473) in Perl.
perl -ne 's/^(\d+)-(\d+)-(\d+)/$1*3600+$2*60+$3/e; print'
But BTW, your math is wrong for the example. 19 * 3600 + 10 * 60 + 13 is 69013.
From what you've written, it's impossible to work out how the transformation you're describing is supposed to work. But this entry from the Perl FAQ may help you to actually change the contents of your file.
How do I change, delete, or insert a line in a file, or append to the beginning of a file?
perl -pi -e 's/^(\d+)-(\d+)-(\d+)/$1*3600+$2*60+$3/e' xyz.txt
That would replace the first column, right in the file.
精彩评论