Click here to Skip to main content
16,016,306 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i'm wanting to assign the builtin variable FNR to a bash script variable, something like this, '$TOT_RECORDS = FNR'



awk '{ print NR-1 "\t" $0; }' $INPUT_FILE >$OUTPUT_FILE

and if i do this, i get each iteration number & i only want the total;

TOT_RECS=$(awk '{ print NR-1; }' $INPUT_FILE)

or this and i do get the total number, but how to assign it to global var?;

awk 'END {print NR}' $INPUT_FILE



via awk, i would like to read the input file, then output to new file with prefix line numbers and return total line numbers into a global script var. what am i missing here besides,
`wc -l` would work without all this hassle. ;-)
Posted

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900