Hello
Is there any sed command to insert a line after nth line... have a file of 500000 lines
Thanks
Hello
Is there any sed command to insert a line after nth line... have a file of 500000 lines
Thanks
Hello,
Here is an awk example for same, it may help.
For example an input file is:
1 5
2 4
3 3
Code is:
awk 'NR==2 {print "checking the insertion."} 1' file_name
Output will be as follows.
1 5
checking the insertion.
2 4
3 3
Thanks,
R. Singh
Insert line after every 7th line:
sed -n 'p;n;p;n;p;n;p;n;p;n;p;n;p;i\inserted line' file_1 >file_2
Try sed with �i� command to insert a line before match for your request to add only one line.
$ cat file.txt
1
2
3
4
5
$ sed "4 i\Inserted new line" file.txt
1
2
3
Inserted new line
4
5
Thank you all for the replies
I ended up writing a small fortran code to do the insertion I was looking for by using
m = 90000
n = 288
do i = 1, m
do j = 1, n
read() original file
write() to the new file
end do
insert line
enddo