0

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
3
  • Please, post the related expected output. Don't post is as a comment, an image, a table or a link to an off-site service but use text and include it to your original question. Also, as this is not a free coding service, we'd appreciate seeing some attempt first. Thanks Commented Jan 13, 2022 at 9:47
  • awk could solve the problem easily. But can you please show what do you have so far? I mean, the script. Commented Jan 13, 2022 at 9:48
  • I tried to grep ORDERID filename | awk pattern , same for elapsed also ..but that gives me wrong matching of orerid and elapsed, @kent Commented Jan 13, 2022 at 9:55

2 Answers 2

1
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 in id, comma is removed from it, and the id, jobname, and elapsed time are printed.
Sign up to request clarification or add additional context in comments.

9 Comments

sed giving me :no such file or directory
@Deepak: Do you mean you don't have sed installed?
yes @choroba ..is there any other way
Do you have awk installed? Or perl?
i have awk installed
|
0

It's not perfect, but it's a start:

grep -i "elapse" test.txt | awk -F " " '{print $7 " " $5 " " $14}'

Comments

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.