Text processing using linux
I have a text 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 status 0.02
2NOO1 PROCESS Kafka 2.28
If there is space in jobname or elapsed or orderid , that also has to be evaluated . Please find the parent version of the question: Parse a text file using shell script.
Important note: sed
is not available.
Bash solution:
#! /bin/bash
set -eu
while read line ; do
if [[ $line =~ JOB' '([^\)]+)'('ORDERID' '([^,]+).*ELAPSED' '-' '([0-9.]+) ]] ; then
echo "${BASH_REMATCH[@]:1:3}"
fi
done < "$1"
It uses bash regex matching to extract the details from the lines that contain "ELAPSED".