Hi,
I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines..
Please help me on this..
Thanks in Advance,
Amrutha
Hi,
I am new to unix. I need to insert a variable which contains some lines of text into a text file after fixed number of lines..
Please help me on this..
Thanks in Advance,
Amrutha
var="ABCD"
#To insert the ABCD after the 3rd line
nawk -v a="$var" '{if(NR==3){print $0;print a}else{print}}' input.txt
---------- Post updated at 02:52 PM ---------- Previous update was at 02:52 PM ----------
bash-3.00$ var="To Insert"
bash-3.00$ cat test.txt
a
b
c
d
e
f
g
bash-3.00$ nawk -v a="$var" '{if(NR==3){print $0;print a}else{print}}' test.txt
a
b
c
To Insert
d
e
f
g
with sed:
$ sed ' 30 a \
New line
' filename
Thanks a lot it works....