LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-05-2013, 06:04 AM   #1
coolpraz
Member
 
Registered: Feb 2010
Posts: 35

Rep: Reputation: 0
Multipal line edited using sed, how to make sed specific


Hi,
im wirting the bash script to change the text from configuration file of httpd.conf, In a configuration file there are many similar lines(likely) to configuration. when i change the text using sed its change the other section tooo. how to overcome form this .
eg: -
Code:
$ cat test.txt

# Timeout: The number of seconds before receives and sends time out.
Timeout 60
#KeepAliveTimeout:
KeepAliveTimeout 15
I used this code to change
Code:
sed -i '/^#/!s/Timeout .*/Timeout 45/' test.txt
When i execute this its change both Timeout 60 and KeepAliveTimeout 15 to Timeout 45 and KeepAliveTimeout 45, However i want to change only value of Timeout 60 not the KeepAliveTimeout 15
 
Old 01-05-2013, 06:53 AM   #2
whizje
Member
 
Registered: Sep 2008
Location: The Netherlands
Distribution: Slackware64 current
Posts: 594

Rep: Reputation: 141Reputation: 141
Code:
bash-4.2$ cat test.txt

# Timeout: The number of seconds before receives and sends time out.
Timeout 60
#KeepAliveTimeout:
KeepAliveTimeout 15
bash-4.2$ sed -i 's/Timeout 60/Timeout 45/' test.txt
bash-4.2$ cat test.txt

# Timeout: The number of seconds before receives and sends time out.
Timeout 45
#KeepAliveTimeout:
KeepAliveTimeout 15
bash-4.2$
 
Old 01-05-2013, 08:48 AM   #3
millgates
Member
 
Registered: Feb 2009
Location: 192.168.x.x
Distribution: Slackware
Posts: 852

Rep: Reputation: 389Reputation: 389Reputation: 389Reputation: 389
Code:
sed -i '/^#/!s/\bTimeout .*/Timeout 45/' test.txt
\b is a metacharacter that matches a "word boundary".

Last edited by millgates; 01-05-2013 at 08:50 AM.
 
Old 01-05-2013, 01:12 PM   #4
coolpraz
Member
 
Registered: Feb 2010
Posts: 35

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by whizje View Post
Code:
bash-4.2$ cat test.txt

# Timeout: The number of seconds before receives and sends time out.
Timeout 60
#KeepAliveTimeout:
KeepAliveTimeout 15
bash-4.2$ sed -i 's/Timeout 60/Timeout 45/' test.txt
bash-4.2$ cat test.txt

# Timeout: The number of seconds before receives and sends time out.
Timeout 45
#KeepAliveTimeout:
KeepAliveTimeout 15
bash-4.2$
Thanx whizje but im using wild card .*, so that whatever time is set its must change that time to 45 sec. I really appricate your help, Thank you whizje
 
Old 01-05-2013, 01:14 PM   #5
coolpraz
Member
 
Registered: Feb 2010
Posts: 35

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by millgates View Post
Code:
sed -i '/^#/!s/\bTimeout .*/Timeout 45/' test.txt
\b is a metacharacter that matches a "word boundary".
Thank you millgates for solving my problem this excatly work for me thank you very much
 
  


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
[SOLVED] Using a variable in sed to pick a specific line from a text file, bash Sunvic Linux - Newbie 10 08-12-2012 11:03 AM
[SOLVED] Need help in replacing set of characters in a specific line using sed or awk bbachu Programming 15 01-03-2011 01:01 AM
[SOLVED] SED and Replacing Specific Line bridrod Linux - Newbie 6 08-24-2009 12:28 PM
SED - replace text in file on specific line 3saul Linux - Software 1 03-04-2006 07:01 PM
Insert character into a line with sed? & variables in sed? jago25_98 Programming 5 03-11-2004 06:12 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 05:51 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
Open Source Consulting | Domain Registration