Copy & Append text

Hi,

I have a huge text file that contains contents like below.

echo 2VPMUM1CMP01_2011-05-10_18_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'
echo 2VPMUM1CMP01_2011-05-11_10_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'
echo 2VPMUM1CMP01_2011-05-12_02_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'
echo 2VPMUM1CMP01_2011-05-10_19_CPU_Stats_1.txt
awk -F, '{sub ("%","",$8);sum+=100-$8;if (100-$8>max){max=100-$8}}END{printf "max=%.1f%\navg=%.1f%\n",max,sum/NR}'

I want to copy the filename that is written after the word echo on 1st line & append it at the end of awk line below it.

Thanks,
Sunil

Try:

awk '{if ((NR %2)== 1){ f = $2;print $0;} else {printf "%s %s\n",$0,f} }'  test.txt

This assumes the alternate occurrance of echo and awk

1 Like

Thanks a lot. This solution is working fine.

Regards,
Sunil