Parse a text file using shell script
I am stuck with this activity ,I have a txt file like below
0112 00000 34 JOB RECOVERY status poll (ORDERID 2N000, RUNNO 0001) ACCEPTED, OWNER
0112 00000 35 JOB RECOVERY status poll (ORDERID 2N000, RUNNO 0001)STARTED , APPL TYPE
0112 00000 36 JOB PROCESS_kafka(ORDERID 2N001, RUNNO 0001) ACCEPTED , OWNER
0112 00001 37 JOB PROCESS_kafka (ORDERID 2N001, RUNNO 0001) STARTED, APPL_TYPE
0112 00001 38 JOB RECOVERY status poll(ORDERID 2N000, RUNNO 0001) ENDED OK ,ELAPSED - 0.02 SEC
0112 00003 39 JOB PROCESS (ORDERID 2N001, RUNNO 0001) ENDED OK, ELAPSED - 2.28 SEC
i need to get elapsed - value for each orderid for each job , i need like if orderid is 2N000, then the elapsed i should get-0.02 sec. like this for each orderid i need to get from the file using shell script.
I need the output like
orderid jobname ELAPSED
2N000 RECOVERY 0.02
2NOO1 PROCESS 2.28
grep ELAPSED file.txt \
| cut -d' ' -f7,5,14 \
| sed -E 's/(.*) ([^[:space:]]+),/\2 \1/'
-
grep
selects just the lines with "ELAPSED"; -
cut
extracts just the columns with orderid, jobname, and elapsed time; - But they are in the wrong order, so
sed
removes the comma from the orderid and reorders the columns.
If sed
is not available, you can use awk
:
awk '/ELAPSED/{id=$7; sub(",", "", id); print id, $5, $14}' file.txt
- On lines containing
ELAPSED
, the seventh value is stored inid
, comma is removed from it, and theid
, jobname, and elapsed time are printed.