Reputation: 1
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.
Upvotes: 0
Views: 75
Reputation: 242168
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".
Upvotes: 2
Reputation: 7832
This suggestion assumes there is only a single whitespace whereas your example text have two whitespaces. And the job have mostly the same number of words and status is "ENDED OK". I have used foreach
from zsh but this can be changed since looping, grepping and cutting are the primary tools.
The input file is called process.txt in this example.
foreach C (`grep "(ORDERID " process.txt|grep " ENDED OK"|cut -d "(" -f 2|cut -d "," -f 1|cut -d " " -f 2`)
line=`grep $C process.txt|grep " ENDED OK"`
job_name=`echo $line|cut -d " " -f 5`
elapsed=`echo $line|cut -d "-" -f 2|cut -d " " -f 2`
echo "$C $job_name $elapsed"
end
Output:
2N000 RECOVERY 0.02
2N001 PROCESS 2.28
Upvotes: 0