I have this following awk
script that takes the following input file, input.txt
and produces the output below. Can someone please take the time to break down how this awk
script works? I've spent a bit of time on it and it's not making a whole lot of sense.
Input:
$ cat input.txt
FINISHED
RSYNCJOBNA
20140502 0021 2182096 2082096 6 5
2014820905820902 10:02:15
2014820905820902 10:56:42
0:54:27
INITIATED
RSYNCJOBNA
20140502 0022 3282096 3182096 6 5
2014820905820902 15:31:06
0:06:04 ce eque**
Output:
RSYNCJOBNA|0021|20140502|10:02:15|10:56:42|0:54:27|FINISHED
RSYNCJOBNA|0022|20140502|15:31:06| |0:06:04|INITIATED
Command to get the above ouput:
awk -v OFS='|' '/FINISHED|INITIATED/ {
status = $1; getline;
jobname = $1; getline;
sequence = $2; date = $1; getline;
start = $2; getline;
if (status == "FINISHED") { end = $2; getline } else { end = " " }
runtime = $1;
print jobname, sequence, date, start, end, runtime, status;
}' input.txt
My understanding is that /FINISHED|INITIATED/ {}
means that the commands inside the curly braces will only be run on lines matching either FINISHED
or INITIATED
but as far as I can tell from the output, the script seems to be parsing from all lines. What's going on?
/FINISHED|INITIATED/
, awk searches for the corresponding line and do the operation only on that particular line.But the operation was performed on all the lines. How? – Avinash Raj May 03 '14 at 08:25