Consider the file test.txt
:
pfg025G
pfg025T
pfg034T
pfg039G
Now consider the following awk command and its output:
awk '(NR>1) {print "s/"p"/"$1"/g"}{p=$1}' test.txt
s/pfg025G/pfg025T/g
s/pfg025T/pfg034T/g
s/pfg034T/pfg039G/g
NR>1
is true for lines greater than one, this is valid for the "$1"
term but not for "p"
which takes the value of the first line. Why is that? Does NR>1
evaluate just the first block {}
and not the second {p=$1}
? Why does the first "$1"
have double quotes ""
while second $1
does not?