Quote:
Originally Posted by berndbausch
Code:
awk '/Fedora/{x=NR+3}NR==x{print "DON"}1' sdf >sdf.temp
|
With this InFile ...
Code:
Fedora
Linux
MAC
Windows
Fedora
Derby
Stetson
Bowler
... et cetera ...
... this code ...
Code:
awk '/Fedora/{x=NR+3}NR==x{print "DON"}1' $InFile >$OutFile
... produced this OutFile ...
Code:
Fedora
Linux
MAC
DON
Windows
Fedora
Derby
Stetson
DON
Bowler
... et cetera ...
Now, let's allow the line to be inserted to be defined externally.
With the same InFile, this code ...
Code:
new="DON"
awk -v new=$new '/Fedora/{x=NR+3}NR==x{print new}1' $InFile >$OutFile
... produced the same OutFile. So far, so good.
Now, let's change the line to be inserted, making it contain blanks.
With the same InFile, this code ...
Code:
new="D O N"
awk -v new=$new '/Fedora/{x=NR+3}NR==x{print new}1' $InFile >$OutFile
... produced an error message ...
Code:
awk: cmd. line:1: fatal: cannot open file `N' for reading (No such file or directory)
How should this be coded?
Daniel B. Martin