Scripting question
I am writing a script.
I would like to know how to replace a line of text in a file, with some new text. Something like: echo "alias eth0 e100" >> /etc/conf.modules But instead of appending at the end of the file, I need it to replace the first line in the file. Thanks for any help! |
If it is the very first line, you can use a combination of wc (word count) and tail.
You would need a temp file. Echo your first line into it. Use wc -l to count the number of lines in the original file. Subtract one from that to get a #. Use tail -n # >> tempfile to cat everything past the first line. Then, replace the original with the tempfile. Of course, somebody will prob'ly come up with a single line replacement command using sed or awk or something. |
Here's one way:
ed << END e /etc/conf.modules 1c alias eth0 e100 . w q END It uses a bash here document and the ed(1) editor. Lyle |
All times are GMT -5. The time now is 12:49 AM. |