I have a text file like this , where the same set of three lines repeat with different values.
INFO: processing now 03/25/2015-00:06:05 03/25/2015-00:16:04
------Invoking myexe table=table1
INFO 25-03 00:20:26,801 - Finished processing (I=0, O=57, R=57, W=57, U=0, E=0)
INFO: processing now 03/25/2015-00:20:09 03/25/2015-00:25:04
------Invoking myexe table=table2
INFO 25-03 00:20:26,801 - Finished processing (I=0, O=57, R=59, W=57, U=0, E=0)
0
Now my requirement is to parse this file and create an output like this.
03/25/2015-00:06:05 03/25/2015-00:16:04 table1 W=57
03/25/2015-00:20:09 03/25/2015-00:25:04 table2 W=57
As each line has a different pattern, I am not sure how to do this in a single shot. Please help. .
This works...
file a.awk contains
/^INFO:/ {
dateTimeSTART=$4
dateTimeEND=$5
}
/^-----/ {
split($0,a,"=")
table=a[2]
}
/^INFO / {
split($10,a,",")
W=a[1]
print dateTimeSTART,dateTimeEND,table,W
Then do
awk -f a.awk input-file > saved.file
1 Like
Hello LakshmiKumari,
Following may help you in same.
awk -F, '/INFO: processing now/{match($0,/[0-9][0-9]\/.*/);A=substr($0,RSTART,RLENGTH);}{if($0 ~ /^-/){gsub(/.*table=/,X,$0);A=A OFS $0;}};{if($0 ~ /Finished processing/){print A OFS $5}}' Input_file
Output will be as follows.
03/25/2015-00:06:05 03/25/2015-00:16:04 table1 W=57
03/25/2015-00:20:09 03/25/2015-00:25:04 table2 W=57
Thanks,
R. Singh
1 Like
RudiC
4
Try also
awk '/^INFO:/ {sub (/^.*now /,""); printf "%s ", $0}
/^-----/ {sub (/^.*=/, ""); printf "%s ", $0}
/^INFO / {sub (/,$/, "", $10); printf "%s\n", $10}
' file
03/25/2015-00:06:05 03/25/2015-00:16:04 table1 W=57
03/25/2015-00:20:09 03/25/2015-00:25:04 table2 W=57
1 Like
Thanks a lot to everyone who replied. It really helps