0

I am executing a command that outputs a table, as such:

firstValue:   a
secondValue:  b.y7
thirdValue:   c-x-g 10:42 GMT

Say I need the secondValue. I can't do this by row number, because sometimes the output could look like this:

firstValue:    a
surprisevalue: d
secondValue:   b.y7
thirdValue:    c-x-g 10:42 GMT

How can I do this by finding a certain string ("secondValue") in the first column, and returning the corresponding string in the second column?

2

Pipe the command through awk; tell it to search for a line that starts with secondValue and output the second field in that line:

$ command-that-outputs-the-table | awk '/^secondValue:/ {print $2}'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.