Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

NR with $var?

Status
Not open for further replies.

mrn

MIS
Apr 27, 2001
3,993
GB
Is this possible?

Code:
SPLIT=40

awk '{
if (NR % ${SPLIT})
printf ("%s #", $0)

NR doesn't seem to like the Var $SPLIT

I've seen examples like

NR % V1 ; V1=$SPLIT

but can't seem to get my head round it.


Mike

"Whenever I dwell for any length of time on my own shortcomings, they gradually begin to seem mild, harmless, rather engaging little things, not at all like the staring defects in other people's characters."
 
A starting point:
awk -v SPLIT=$PLIT '{
if (NR % SPLIT)printf ("%s #", $0)
...

Hope This Helps, PH.
FAQ219-2884
FAQ181-2886
 
In other words... awk variables are not shell variables. If you were to surround your awk script in single-quotes instead of double-quotes then the shell would interpolate them into the script (which may be what you have seen elsewhere), however this can be awkward because it means escaping any other characters which you need to be preservd for awk, for example \$0.

There's a typo in PHV's post, PLIT should of course be SPLIT.

Annihilannic.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top