0
31400     371    2946    3966   12378      82     185     206      46       1

I want to write a script that will always extract the second number from a script like the one above i.e. 371. The number changes each time I run the script. Any ideas what bash command to use to extract just the number 371 but that number could be anything.

4

This is exactly the sort of thing that awk is for:

$ ./yourscript.sh | awk '{print $2}'
371
0

Or

cut -f2 file

presumed the data are Tab separated.

0

Or

./yourscript.sh | { read a b c; echo $b; }

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.