output redirection

Hi all

I was wondering if there was a slicker way of doing this without the file -

awk '{print $2}' FS=":" "${FILE}" > "${TMPFILE}"
 
{    
      read M_GRP_ID || m_fail 1 "Error: Read failed 1 (${FUNCNAME})" 
      read M_GRP_WAIT || m_fail 1 "Error: Read failed 2 (${FUNCNAME})"
} < "${TMPFILE}"

How could I redirect the output of the awk straight into the reads without using an intermediate file?

Thanks in advance

Steady

Can't you just use a pipe?

$ echo "some pie" | awk '{print $2}' | { read ONE || echo TWO ; read THREE || echo FOUR; }
FOUR

Use a pipe to supply input to the code block:

awk '{print $2}' FS=":" "${FILE}" | {    
      read M_GRP_ID || m_fail 1 "Error: Read failed 1 (${FUNCNAME})" 
      read M_GRP_WAIT || m_fail 1 "Error: Read failed 2 (${FUNCNAME})"
}
1 Like

Hi,

I dont know, What OS and Shell you are using??
But in BASH, you can use like below,

awk 'BEGIN{FS=":";}{print $2;}' file1|while read M_GRP_ID
do
   read M_GRP_WAIT
   echo ${M_GRP_ID}
   echo ${read M_GRP_WAIT}
done

Cheers,
Ranga :slight_smile:

That code in parentheses runs in a sub-shell. If you ever want to refer to the variables ONE and/or THREE , you'll not be able to.

Yeah, that's a typo/not paying attention error...

Thanks for all the help guys

The pipe was the most suitable for what I wanted :slight_smile:

Cheers