Click to See Complete Forum and Search --> : [Bash] Replace a single line in a document


hop-frog
06-19-2003, 02:02 PM
I understand I can use > to send text to a document and >> to ammend text to a document. What do I use to replace (ex.) line 15 in a text document with another line?

Hayl
06-19-2003, 02:12 PM
afaik you need to write a script in something such as perl for that.

JohnT
06-19-2003, 02:19 PM
Originally posted by hop-frog
I understand I can use > to send text to a document and >> to ammend text to a document. What do I use to replace (ex.) line 15 in a text document with another line?


I prefer "Gedit" most of the time, but there are several.

:p

Strogian
06-19-2003, 02:20 PM
I'd use sed. :)

arn0ld
06-19-2003, 02:37 PM
you can use ex in batch mode
ex myfile<<!
15s/^.*$/new stuff/
w
q
!

this can be used in a script where myfile=$1 and "new stuff" =$2

sploo22
06-19-2003, 02:47 PM
With sed, to change line 15 to "ooooh pretty colors", do this:

sed -e '15s/^.*$/ooooh pretty colors/' < file > /tmp/tempfile
rm file
mv /tmp/tempfile file

hop-frog
06-19-2003, 03:12 PM
Thanks.