Concat Two Command Result in File Concat Two Command Result in File unix unix

Concat Two Command Result in File


For example:

a=`cat BIG_DATAfinal.txt | grep "STATUS" | awk '{print $5}'`b=`cat BIG_DATAfinal.txt | grep "start" | awk '{print $3}' | sed 's/time;//g'`echo "$a;$b"


You can do this with a single awk program:

awk -v OFS=";" '    /STATUS/ {status=$5}     /start/ {split($3, a, /;/); start=a[2]}     status && start {print status, start; status=start=""}' BIG_DATAfinal.txt

If the output looks like ;2015-03-30o, then your file has \r\n line endings, and you should do this:

sed 's/\r$//' BIG_DATAfinal.txt | awk -v OFS=";" '    /STATUS/ {status=$5}     /start/ {split($3, a, /;/); start=a[2]}     status && start {print status, start; status=start=""}'