Piping a bash variable into awk and storing the output

Posted by Andrew Smith on Stack Overflow See other posts from Stack Overflow or by Andrew Smith
Published on 2010-03-22T03:17:16Z Indexed on 2010/03/22 3:21 UTC
Read the original article Hit count: 371

Filed under:
|

Hello,

To illustrate my problem,

TEST="Hi my name is John"
OUTP=`echo $TEST | awk '{print $3}'`
echo $OUTP

What I would expect this to do is pass the $TEST variable into awk and store the 3rd word into $OUTP.

Instead I get "Hi: not found", as if it is expecting the input to be a file. If I pass just a string instead of a variable, however, there is no problem. What would be the best way to approach this?

Thanks all!

© Stack Overflow or respective owner

Related posts about awk

Related posts about bash