Reputation: 1119
I have a file: START.txt
with lines like:
13.03.2013 12:13:42|STRING1|NUMBER1|NUMBER2|NUMBER3
and I want change all the lines from this file to the following format:
12:13|STRING1|NUMBER1|NUMBER2|NUMBER3
How can this be done?
Upvotes: 0
Views: 504
Reputation: 41456
Here is an awk
awk '{sub(/:[0-9]+\|/,"|",$2);print $2}' file
12:13|STRING1|NUMBER1|NUMBER2|NUMBER3
Just delete seconds from the second part and print it.
Upvotes: 3
Reputation: 174706
Try this GNU sed
command,
$ sed -r 's/^[^ ]+? ([0-9]{2}:[0-9]{2}):[0-9]{2}(.*)$/\1\2/g' file
12:13|STRING1|NUMBER1|NUMBER2|NUMBER3
And through awk,
$ awk -F'|' -v OFS='|' '{sub (/^[^ ]+? /,"",$1); sub (/:[0-9]{2}$/,"",$1);}1' file
12:13|STRING1|NUMBER1|NUMBER2|NUMBER3
Upvotes: 2
Reputation: 77095
Using awk
:
$ awk 'BEGIN{FS=OFS="|"}{split($1,fld,/[.: ]/);$1=fld[4]":"fld[5]}1' file
12:13|STRING1|NUMBER1|NUMBER2|NUMBER3
|
. .
and :
and put the values in an array fld
. 1
you print the line (which is idiomatic way of saying {print $0}
. Upvotes: 1
Reputation: 1106
Using this pattern should match each line and capture the portion that you wish to retain:
^\d{2}\.\d{2}\.\d{4}\s(.*)$
You can see an example of the pattern in action here: http://regexr.com/38vq0
Upvotes: 1