Reputation: 31
I have a file xyz.txt
containing the following information:
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.
Upvotes: 0
Views: 510
Reputation: 399
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.
Upvotes: 0
Reputation: 42674
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.
Upvotes: 2
Reputation: 69244
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?
Upvotes: 0