About the awk command to show a range of specific lines the following tutorial is valuable
See the Another use of NR built-in variables (Display Line From 3 to 6) section
Therefore if a range of lines is desired the following code works fine
awk 'NR==1, NR==7 {print NR,$0}' somefile.txt
Until here it is ok, now consider the following scenario, it works too
awk 'NR==7, NR==7 {print NR,$0}' somefile.txt
Yes, NR is the same as 7. It only shows the line 7
The goal is through a shell script show the current line, it line by line.
To accomplish this goal, the following attempt code was created but it does not work
CURRENT_LINE=7
echo "CURRENT_LINE: $CURRENT_LINE"
awk 'NR==$CURRENT_LINE, NR==$CURRENT_LINE {print NR,$0}' somefile.txt
In this case awk shows nothing.
Even with (see that ' was replaced by ")
awk "NR==$CURRENT_LINE, NR==$CURRENT_LINE {print NR,$0}" somefile.txt
fails with:
CURRENT_LINE: 7
awk: cmd. line:1: NR==7, NR==7 {print NR,./Dictionary.sh}
awk: cmd. line:1: ^ syntax error
awk: cmd. line:1: NR==7, NR==7 {print NR,./Dictionary.sh}
awk: cmd. line:1: ^ unterminated regexp
awk: cmd. line:1: NR==7, NR==7 {print NR,./Dictionary.sh}
awk: cmd. line:1: ^ unexpected newline or end of string
Therefore is mandatory use '' and not ""
Therefore What is missing? and How to accomplish this goal?