Cut Command Not Working in Pipe – Troubleshooting Guide

cutgrep

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?

Best Answer

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.

Related Question