Domanda

The output of certain command contains

 >> ..................546 Jobs Retrieved 
    List of jobs Retrieved: 1-4,6-12,14,2017-2018 ............
 >>> 30 Jobs Done
    Jobs terminated: retrieve them with: crab -getoutput <List of jobs>
    List of jobs: 203,376,578,765,803,809,811
.....................

And I want to extract only 203,376,578,765,803,809,811 that occurs after line 30 Jobs Done. And after that I neet to put this number as a string in certain variable to use this in some command. How can I do it.

I tried it in this way:

  1. I put the output in a status.log file
  2. $ sed -e '1,/Jobs Done/d' status.log | grep "List of jobs:" then I got only line List of jobs: 578,765,811,836,1068,1096,1128 but I don't need the phrase "List of jobs"

Please help me.

Thank you very much in advance.

È stato utile?

Soluzione

You can use this:

awk '/30 Jobs Done/ {f=1;next} f && /List of jobs:/ {print $4;exit}' file
203,376,578,765,803,809,811

When it find 30 Jobs Done it set flag f to true.
If it then finds List of jobs: and flag f is true, print field 4

Altri suggerimenti

Using simple tools:

egrep '^\s+List of jobs: [0-9,]+$' status.log | cut -d: -f2

The pattern for egrep matches the whole line and the cut returns everything after the :.

That means you will get a leading space in the result. If that's a problem:

egrep '^\s+List of jobs: [0-9,]+$' status.log | cut -d: -f2 | cut -c2-

You could do this:

grep -A2 "Jobs Done" yourfile | awk '/List of jobs:/{print $4}'

Grab two lines following "Jobs Done" (-A2) and then look for "List of jobs" with awk and print 4th field.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top