LinuxQuestions.org
Visit Jeremy's Blog.
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 06-26-2013, 03:59 AM   #1
gurumoha
LQ Newbie
 
Registered: Jun 2013
Posts: 1

Rep: Reputation: Disabled
how to replace below lines with mutliple occuences using sed


here is my sed expression

sed -i -e "s/\(.\)\(.*\).org.apache.juli.FileHandler.directory = \(.*\)/\1\2.org.apache.juli.FileHandler.directory = $newloglocation/g" logging.properties


and below are the lines that has to be replaced with new loggign location.



1catalina.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
2localhost.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
3manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs
4host-manager.org.apache.juli.FileHandler.directory = ${catalina.base}/logs

here i am trying to replace the string "${catalina.base}/logs" with new path.


when i ran the sed command am getting the below exception

sed: -e expression #1, char 108: unknown option to `s'

Last edited by gurumoha; 06-26-2013 at 04:02 AM. Reason: more input
 
Old 06-26-2013, 06:13 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402Reputation: 2402
A path contains forward slashes, and so will $newloglocation. You also use forward slashes in sed to separate the search from the replace part (s/../../).

These two won't go together.

In general you need to escape the forward slashes in the path, but in this case that might be problematic (it is contained in a variable).

In this specific case I would change the forward slashes used by sed to something else (any character can be used). A pipe character might do the trick:
Code:
sed -i -e "s|\(.\)\(.*\).org.apache.juli.FileHandler.directory = \(.*\)|\1\2.org.apache.juli.FileHandler.directory = $newloglocation|g" logging.properties
 
Old 06-26-2013, 06:22 AM   #3
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Mint 17.3
Posts: 1,855

Rep: Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655Reputation: 655
Help us to help you. You gave a sample input file (that's good) and some words (also good). Construct a sample output file which corresponds to your sample input and post it here. With "Before and After" examples we can better understand your needs and also judge if our proposed solution fills those needs.

Daniel B. Martin
 
Old 06-26-2013, 07:08 AM   #4
Firerat
Senior Member
 
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
Well,
Code:
sed -i -e "s/\(.\)\(.*\).org.apache.juli.FileHandler.directory = \(.*\)/\1\2.org.apache.juli.FileHandler.directory = $newloglocation/g" logging.properties
it seems to work just fine here, no changes
sed (GNU sed) 4.2.2
GNU bash, version 4.2.45(1)-release (x86_64-pc-linux-gnu)



but why not just do
Code:
sed 's/apache.juli.FileHandler.directory.*/apache.juli.FileHandler.directory = $newloglocation/' logging.properties
or even

Code:
sed 's[${catalina.base}/logs[${newloglocation}/logs[' logging.properties
I'm sure I'm missing something..
But as it stands that last one fits what I see you asking for.
assumes catalina.base is currently unique to apache.juli.FileHandler.directory
 
  


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
sed replace pattern on all lines except those with pattern1, pattern2, pattern3... Jykke Programming 3 06-22-2012 10:32 AM
[SOLVED] Sed -> Search on 2 consecutive lines and then replace lebrocoli Programming 3 04-27-2012 02:20 PM
[SOLVED] sed - replace alternate occurrences (on different lines) gazzatav Programming 5 04-16-2011 11:46 AM
need sed help - how to replace all instances of X except those on lines with Y? BrianK Programming 4 03-25-2008 06:49 PM
replacement with sed: replace pattern with multiple lines Hcman Programming 5 11-18-2004 07:40 AM

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

All times are GMT -5. The time now is 07:57 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