0

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.

12
  • Do you have perl installed? Commented Jan 14, 2022 at 8:26
  • Why is RECOVERY status the job name and not RECOVERY status poll? Commented Jan 14, 2022 at 8:26
  • sorry that was my mistake, we need RECOVERY status poll Commented Jan 14, 2022 at 8:35
  • no i dont have perl , i need to do it using linux shell Commented Jan 14, 2022 at 8:36
  • 1
    What shell do you use? Commented Jan 14, 2022 at 9:50

2 Answers 2

2

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".

Sign up to request clarification or add additional context in comments.

Comments

0

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

5 Comments

what if i have something like Recovery status poll as jobname?
I was a bit imprecise. Jobname can be anything.
yeah..if there is single space or double space between words of jobname ?
and i cant remove the space between jobname , since at last i need to load all these to table, i need the jobname exact as what it is
If there are uknown number of whitespace the cut-command that use space (" ") as delimiter won't work as intended. So the output must be formatted to use only a single whitespace.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.