2

I'm building a one liner in bash.
If making a script or writing temp files were an option, I wouldn't need to ask.

I need to assign a variable in the middle of a set of pipes to use down the line.

    cat list | awk '{print $1".modifications_to_name"' | (capture $NAME and pass $NAME down pipe) \
    | checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME
3
  • Is there output from the awk that is not part of $NAME or how would you distinguish which parts should he NAME and which are only to be handled by checkStatus? Perhaps some sample input and desired output would help clarify what you want Commented Feb 12, 2016 at 18:51
  • Why do you need to use pipes? You can use ; to break up lines as though you ere writing a script. Thus it is still one line. something like: NAME=`cat list | awk '{print $1".modifications_to_name"}'`; echo $NAME | checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert
    – Kip K
    Commented Feb 12, 2016 at 18:57
  • Eric, the $NAME should always be the modified version.. the original list can be discarded. ............................ Kip, I don't need pipes, just learning to "Embrace the single line".The backticks cause the line delimited list to become space delimited, which checkStatus will choke on. Commented Feb 13, 2016 at 0:10

1 Answer 1

1

Disregarding that your awk is missing a brace, and assuming list contains a single line, why not: NAME=$( cat list | awk '{print $1".modifications_to_name"') && checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME

If you want to iterate through a list with multiple lines and have name evaluate to something different each time:

while read NAME; do checkStatus | grep pertinentinfo | cleanupFormatOfPertinentInfo | sendAlert $NAME ; done < <(cat list | awk '{print $1".modifications_to_name"')

This seems like an X Y question though.

1
  • Thank You. It was a total X_Y question. Because I had good ways to avoid the problem, I wanted to expand my skillset. And I didn't want a bunch of noisy answers. The second part of your answer handles what I need elegantly. I was/am hoping that someone would explain that there is a command/trick like tee for variables, rather than tee for files. Commented Feb 12, 2016 at 23:57

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .