Girish
Girish

Reputation: 13

add expr within awk

I am trying to increment record number variable (NR) within awk script like below but getting syntax errors.

awk '{print "dm" `expr $NR + 225` "," $0}'  test

where test is a text file with numerous records.

Appreciate if someone can help me with the correct syntax !

Upvotes: 0

Views: 3134

Answers (1)

Kent
Kent

Reputation: 195219

I don't know why you need to do in this way. how about:

awk '{print "dm" NR+255","$0}'  test

also in your codes, the $NR was wrong.

well if answer your question straightly, your awk line should be written like:

awk '{"expr "NR" + 225"|getline n; print "dm" n ","$0}' test

Upvotes: 1

Related Questions