10

I am able to filter out jobs which got stuck in our queueing system with:

> qjobs | grep "racon" 
       5240703 racon-3/utg001564l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :03   
       5241418 racon-3/utg002276l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :02   
       5241902 racon-3/utg002759l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :03   
       5242060 racon-3/utg002919l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :04   
       5242273 racon-3/utg003133l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :03   
       5242412 racon-3/utg003270l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :04   
       5242466 racon-3/utg003325l-racon-3.fasta  H   1     1   0     10.0   0.0    150   :03   

However, qjobs | grep "racon" | cut -d " " -f2 did not return e.g. racon-3/utg003325l-racon-3.fasta. What did I miss?

3 Answers 3

25

Every space counts towards the field number, even leading and consecutive ones. Hence, you need to use -f9 instead of -f2. Alternatively, you can use awk '{ print $2 }' in place of the cut command entirely.

1
  • 13
    If OP is going to use awk anyway, they can fold it together with the grep operation: qjobs | awk '/racon/ { print "$2" }'. Dec 29, 2019 at 10:27
1

If the output is consistent in its spacing

qjobs | grep "racon" | cut -c 16-47

would produce output like

racon-3/utg002276l-racon-3.fasta

If you want the first column, which looks like a PID or some other identifier, then:

qjobs | grep "racon" | awk ' { print $1 } '

If you're looking for the utg002276l part which looks something like a username:

qjobs | grep "racon" | awk -F'[/-]' ' { print $3 } '

This makes awk use the slash and dash characters as field separators, and then prints the third column.

0

You could squeeze all the spaces into one:

qjobs | grep "racon" | tr -s ' ' | cut -d " " -f3

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .