awk - extracting data from a series of files

Hi,
I am trying to extract data from multiple output files.

I am able to extract the data from a single output file by
using the following awk commands:

awk '/ test-file*/{print;m=0}' out1.log > out1a.txt
awk '/ test-string/{m=1;c=0}m&&++c==3{print  $2  "  "  $3   "  "  $4  ;m=0}' out1.log > out1b.txt
awk '/ test-string/{m=1;c=0}m&&++c==13{print  $2  "  "  $3   "  "  $4  ;m=0}' out1.log > out1c.txt

Now, how to extract data from multiple output files, say out1.log, out2.log, out3.log in a single step?

Any suggestions on how to combine the second and third awk commands to a single command [as the commands output 'line 3' and 'line 13' respectively, after the common 'string'].

Thanks for all your help!!:rolleyes:

Try:

awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4}m&&c==13{print $2 " " $3 " " $4 ;m=0}' out1.log > out1c.txt

Thanks, Bartus. The code works. Any thoughts about extracting data from multiple output files??:cool:

Try:

for i in out1 out2 out3; do 
awk '/ test-file*/{print;m=0}' $i.log > ${i}a.txt
awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4}m&&c==13{print $2 " " $3 " " $4 ;m=0}' $i.log > ${i}c.txt
done

Thanks Bartus!!

The code works well, and it writes out out1a.txt, out2a.txt, out2a.txt. If I need only one output (for the first awk command, out1a.txt) with all the data extracted sequentially into it from out1.log, out2.log and out3.log, what do I need to do? When I replace '${i}' with out1a.txt, only data from out1.log gets extracted. Thank You!:rolleyes:

rm -f outa.txt
for i in out1 out2 out3; do 
   awk '/ test-file*/{print;m=0}' $i.log >> outa.txt
   awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4}m&&c==13{print $2 " " $3 " " $4 ;m=0}' $i.log > ${i}c.txt
done

Hi Chubler,
It doesn't do the trick. I guess it is overwriting the first output. Any other suggestions? Thank you:)

Are you sure your looking at "outa.txt" and not "outa1.txt" or "outa2.txt" from the previous version of the program?

Hi Chubler.

I ran the script after changing the names - to avoid the confusion. The result is the same, I see only the data extracted from out3.log. Thanks! :cool:

Any suggestions please.. Eager to try out you suggestions so that it takes care of my looong analysis. Thanks a lot:)

Try this and check your outa.log file then:

rm -f outa.txt
for i in out1 out2 out3; do 
   echo "===== Processing file $i =====" >> outa.txt
   awk '/ test-file*/{print;m=0}' $i.log >> outa.txt
   echo "===== Finished with file $i =====" >> outa.txt
   awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4}m&&c==13{print $2 " " $3 " " $4 ;m=0}' $i.log > ${i}c.txt
done

Thank you Chubler. The code worked great. I appreciate your time and help!!!:wink:
However, if I have to repeat the same for second awk (I have made a separate
script), it doesn't work.

rm -f outb.txt
for i in out1 out2 out3; do
echo "===== Processing file $i =====" >> outb.txt
awk '/ test-string/{m=1;c=0}m&&++c==3{print $2 " " $3 " " $4}m&&c==13{print $2 " " $3 " " $4 ;m=0}' $i.log >> outb.txt
echo "===== Finished with file $i =====" >> outb.txt
done

cat out*.log | awk ....