LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 01-28-2010, 04:34 PM   #1
replica88
Member
 
Registered: Nov 2009
Posts: 48

Rep: Reputation: 18
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
root		(hd0,0)
kernel		/boot/vmlinuz-2.6.24-24-generic root=UUID=b09feb23-5524-4ec4-862f-94700b968f64 ro quiet splash
initrd		/boot/initrd.img-2.6.24-24-generic
quiet

title		Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic (recovery mode)
root		(hd0,0)
kernel		/boot/vmlinuz-2.6.24-24-generic root=UUID=b09feb23-5524-4ec4-862f-94700b968f64 ro single
initrd		/boot/initrd.img-2.6.24-24-generic

title		Ubuntu 8.04.3 LTS, memtest86+
root		(hd0,0)
kernel		/boot/memtest86+.bin
quiet
I need to add acpi=force to two lines as below

Code:
title		Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic
root		(hd0,0)
kernel		/boot/vmlinuz-2.6.24-24-generic root=UUID=b09feb23-5524-4ec4-862f-94700b968f64 ro quiet splash acpi=force
initrd		/boot/initrd.img-2.6.24-24-generic
quiet

title		Ubuntu 8.04.3 LTS, kernel 2.6.24-24-generic (recovery mode)
root		(hd0,0)
kernel		/boot/vmlinuz-2.6.24-24-generic root=UUID=b09feb23-5524-4ec4-862f-94700b968f64 ro single acpi=force
initrd		/boot/initrd.img-2.6.24-24-generic

title		Ubuntu 8.04.3 LTS, memtest86+
root		(hd0,0)
kernel		/boot/memtest86+.bin
quiet
Any ideas?
 
Old 01-28-2010, 04:45 PM   #2
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
Code:
sed -i '/^kernel/s/$/ acpi=force/' menu.lst
Test it first without the "-i" flag
 
Old 01-28-2010, 04:49 PM   #3
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
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
will create a backup copy named file.bck, before editing file. Maybe you already know all of this, but it's worth to mention for safety.

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
Don't forget the space before "apci".

Edit: too late... sorry for redundancy. Pixellany, I envy your ability to be clear and succinct...

Last edited by colucix; 01-28-2010 at 04:53 PM.
 
Old 01-28-2010, 05:25 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
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

Last edited by Tinkster; 01-28-2010 at 05:29 PM.
 
Old 01-28-2010, 05:50 PM   #5
colucix
LQ Guru
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983Reputation: 1983
Quote:
Originally Posted by Tinkster View Post
Because i don't know whether memtest will handle the acpi=force
He he.. that's right!
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Insert line into a file with a command guif Linux - Newbie 2 01-04-2010 02:43 PM
How to copy command line commands into a text file... visitnag Linux - Newbie 6 04-26-2009 04:11 AM
Command to print last line of a text file Micro420 Linux - General 3 01-25-2007 01:17 AM
Passing a text file to the command line as arguments wimnat Linux - General 2 12-05-2005 08:09 AM
chpasswd from a command line (without a text file) mpgram Linux - Security 1 04-18-2004 05:44 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:37 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration