output 2 files using awk

Hi guys,

Basically, I have an END {print NR} statement in my awk script to count the number of records as I have concatenated multiple files. But instead of generating this total number of records to the same output data file. I want to put this in a separate control file using the same awk script.

How can this be done? Can I specify a separate output file for this END {print NR} statement for the same awk script?

Thanks!

Try this,

END {print NR > "recno.out"}
1 Like

thanks dude!!!!

END {print NR > "recno.out"}

What if I want to parameterize this output file from print NR? I can't seem to make it work.. anyone?

BusDt=2011-02-14
awk -v BusDt="$BusDt" -F"|" '{print $0 FILENAME} END {print NR > "$BusDt.ctl"}' SOURCE/*.pretxt > ${BusDt}.txt

It's writing to $BusDt.ctl instead of 2011-02-14.ctl

Try this,

awk -v BusDt="$BusDt" -F"|" '{print $0 FILENAME} END {print NR > BusDt".ctl"}' SOURCE/*.pretxt > ${BusDt}.txt
1 Like

man, thank you again! please keep on checking my posts.. I'd really be needing your help :smiley: all the best :smiley:

awk -v BusDt="$BusDt" -F"|" '{print $0 FILENAME} END {print NR > "'$BusDt'.ctl"}' SOURCE/*.pretxt > ${BusDt}.txt

use the above command...