Visit Jeremy's Blog.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 06-26-2013, 03:59 AM   #1
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/\(.\)\(.*\) = \(.*\)/\1\ = $newloglocation/g"

and below are the lines that has to be replaced with new loggign location. = ${catalina.base}/logs = ${catalina.base}/logs = ${catalina.base}/logs = ${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
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:
sed -i -e "s|\(.\)\(.*\) = \(.*\)|\1\ = $newloglocation|g"
Old 06-26-2013, 06:22 AM   #3
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
Senior Member
Registered: Oct 2008
Distribution: Debian sid
Posts: 2,683

Rep: Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783Reputation: 783
sed -i -e "s/\(.\)\(.*\) = \(.*\)/\1\ = $newloglocation/g"
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
sed 's/*/ = $newloglocation/'
or even

sed 's[${catalina.base}/logs[${newloglocation}/logs['
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


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 07:57 PM.

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