Extract one word after a specific word on the same line [duplicate]

With awk:

awk '{for(i=1;i<=NF;i++) if ($i=="--pe_cnt") print $(i+1)}' inputFile

Basically loop over each word of the line. When you find the first you are looking for, grab the next word and print it.

With grep:

grep -oP "(?<=--pe_cnt )[^ ]+" inputFile

Leave a Comment