insert text to a file using command line
I need to be able to edit a file from the commend line as I intend to script this operation, the file is called menu.lst
The original is as below Code:
title Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic Code:
title Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic |
Code:
sed -i '/^kernel/s/$/ acpi=force/' menu.lst |
The most straightforward method to edit a file using a command is by means of the sed editor. If you're already familiar with it, take in mind you can edit the file in place using the option -i. But always do a backup copy of your original file, until you're sure the result is exactly as your expectations. sed permits to do this automatically, just by adding a suffix to the option -i, e.g.
Code:
sed -i.bck <sed command here> file Regarding your question, using sed you can just address the lines containing the keyword "kernel" at the beginning and add " acpi=force" at the end. For example: Code:
sed '/^kernel/ s/$/ apci=force/' menu.lst Edit: too late... sorry for redundancy. Pixellany, I envy your ability to be clear and succinct... :) |
Slight modification
Code:
sed -i '/^kernel \/boot\/vmlinuz/s/$/ acpi=force/' menu.lst Because i don't know whether memtest will handle the acpi=force |
Quote:
|
All times are GMT -5. The time now is 04:09 PM. |