LinuxQuestions.org
Latest LQ Deal: Linux Power User Bundle
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 02-09-2012, 11:37 AM   #1
finekevin
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Rep: Reputation: Disabled
Replace a line using sed


Hi,

Hi Linux Gurus,
I need your help!

1) How do we replace the following link with new timeout value in a file using "sed".

timeout 5 ===> timeout 10

Note: I don't know the space/tab between "timeout" string and the value "5".

I can't key on "timeout" or "5" since the file contains the following timeout string and many 5's.
terminal --timeout=15 serial console

2) How do I add the following string at the end of the file using "sed".
riohdid=0


Thank you,
Kevin
 
Old 02-09-2012, 12:40 PM   #2
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by finekevin View Post
Hi,
Hi Linux Gurus,I need your help!

1) How do we replace the following link with new timeout value in a file using "sed".
timeout 5 ===> timeout 10

Note: I don't know the space/tab between "timeout" string and the value "5". I can't key on "timeout" or "5" since the file contains the following timeout string and many 5's. terminal --timeout=15 serial console
You should find out how many spaces/tabs between, or is it variable, and do you need the output in a static or variable form? You can use
Code:
sed 's/timeout *5/timeout 10/g'
which will replace 'timeout <several spaces>5' with 'timeout 10' (one space). If you need the number of spaces to match/be adjusted, that's different.
Quote:
2) How do I add the following string at the end of the file using "sed".
riohdid=0
Why use sed? Just typing in "echo "riohdid=0 >> <filename>" will put that string at the end of a file.
 
Old 02-09-2012, 12:41 PM   #3
Satyaveer Arya
Senior Member
 
Registered: May 2010
Location: Palm Island
Distribution: RHEL, CentOS, Debian, Oracle Solaris 10
Posts: 1,415

Rep: Reputation: 305Reputation: 305Reputation: 305Reputation: 305
Check out these threads, it may help you:

http://www.linuxquestions.org/questi...t-file-594551/
http://www.unix.com/unix-dummies-que...-new-line.html
 
Old 02-09-2012, 12:44 PM   #4
finekevin
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Thank you very much!
 
Old 02-22-2012, 04:04 PM   #5
finekevin
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
You should find out how many spaces/tabs between, or is it variable, and do you need the output in a static or variable form? You can use
Code:
sed 's/timeout *5/timeout 10/g'
which will replace 'timeout <several spaces>5' with 'timeout 10' (one space). If you need the number of spaces to match/be adjusted, that's different.

Why use sed? Just typing in "echo "riohdid=0 >> <filename>" will put that string at the end of a file.
The "echo" attaching "^M" end of each line. This is not good, since I am modifying the grub.conf
 
Old 02-23-2012, 09:52 AM   #6
TB0ne
LQ Guru
 
Registered: Jul 2003
Location: Birmingham, Alabama
Distribution: SuSE, RedHat, Slack,CentOS
Posts: 17,926

Rep: Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690Reputation: 3690
Quote:
Originally Posted by finekevin View Post
The "echo" attaching "^M" end of each line. This is not good, since I am modifying the grub.conf
Well, you did not say you were modifying grub.conf, so there's no way we can know. And if there is a ^M, then read the man page on the echo statement. Pay particular attention to the "-n":
Code:
-n     do not output the trailing newline
 
Old 02-23-2012, 02:14 PM   #7
finekevin
LQ Newbie
 
Registered: Jan 2012
Posts: 6

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by TB0ne View Post
Well, you did not say you were modifying grub.conf, so there's no way we can know. And if there is a ^M, then read the man page on the echo statement. Pay particular attention to the "-n":
Code:
-n     do not output the trailing newline
It works! Thank you!
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
[SOLVED] sed help - replace line feed with different character bradvan Programming 7 04-23-2012 12:31 AM
sed - How do you replace end of line with a space pppaaarrrkkk Programming 7 02-07-2011 12:27 PM
SED replace specyific line with variable zwierzq Linux - Software 4 01-23-2010 10:23 PM
SED - replace line after substing rany Linux - Newbie 2 07-02-2009 02:13 AM
replace a pattern with a line using sed/awk lokeshn05 Linux - Newbie 3 05-06-2009 04:01 PM


All times are GMT -5. The time now is 06:40 PM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration