Assume that the environment variable N contains a number.
awk "NR>N"
What should I do if I want to use the value of the variable in the awk script as shown in ?
linux shellscript zsh
Use the awk -v
option.
awk-vN="$N"'NR>N'
Another possible method is to use shell variable expansion.
awk "NR>$N"
However, there are two disadvantages to this method.
Example 2:
$CMD='; print "piyopiyo"'
$ awk "BEGIN {print$CMD}"
piyopiyo
$ awk-vCMD = "$CMD" 'BEGIN {printCMD}'
; print "piyopiyo"
© 2024 OneMinuteCode. All rights reserved.