I need a little help learning to batch an awk script. All the examples I found on line are too complicated for me. Here's the awk command that I want to run on lots of files.
#!/bin/ksh
for i in 1 2 3 4 5
do
awk 'NR==FNR{a[$1]=$0;next} $3 in a{print $0,a[$1], a[$3]}' "inputfile_A_${i}.out" "inputfile_B_${i}.out" > "outputfile${i}.txt"
done
raj, your code works well although it does create an extraneous column of data (column 8) that doesn't appear to correlate to anything in the two input files, and it also leaves out one column of data, but I can live with these. Also, I had to remove the $3 in the print statement
raj, the output files from your code get named: outputfile1.txt outputfile1+1.txt outputfile2+1.txt etc. is there a simple way for it to add the values together
elixir, your code also ran on the files, but only gave one output file that the data was from the last set of inputfiles in the directory. I think all the previous are getting overwritten. Your code produced two extraneous columns of data that doesn't correlate to either of the inputfiles. Columns 6 and 9
I really realy thank you guys sooo much for helping me, hopefully these little qwerkies are easy to fix???
atjurhs I had not made any changes to your code related to output of column in awk statment.
As for the file name is concerned check the value of $i coming in the code on your system. As for me its giving correct value. Try replace ${i} with $i also in output file name.
If still not working get back to me with $i value.