You are not logged in.
I'd like to do something like...
echo "This is the new line 5." > file.txt(5)
where file.txt is an existing file. Does anyone know of a way to do this? If it can't be done via command-line, I'm okay with using C if someone knows how to do it in C...
Last edited by tony5429 (2009-03-01 04:56:31)
Offline
you could try using the insert functionality of the sed command
Offline
Oh... How can I do that exactly?
Offline
The lazy/inefficient way would be, to insert at line x, the following:
head file -n (x-1) > newfile
echo "my line" >> newfile
tail file -n +x >> newfile
mv newfile file
But if you don't really care about efficiency, it's simple and works.
Offline
Thanks; this solution works for me. One minor item to point out, I had to use tail file -n +(x+1) >> newfile for the third line there.
Offline
edit: nevermind, i guess you already solved it
Last edited by evr (2009-03-01 05:00:06)
Offline