LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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 07-21-2008, 09:49 AM   #1
maker10
LQ Newbie
 
Registered: Aug 2003
Posts: 15

Rep: Reputation: 0
Another problem with sed


Hi All,

I am having a problem writing a one liner that will find some text in a script; comment it out; and then insert a new line underneath.

Here is what I mean:

Find: MOZ_LIB_DIR="/usr/lib64"

Insert Comment: #MOZ_LIB_DIR="/usr/lib64"

Add new line: MOZ_LIB_DIR="usr/lib"

Code:

sed 's/MOZ_LIB_DIR=\"/usr/lib64\"/#MOZ_LIB_DIR=\"/usr/lib64\"\nMOZ_LIB_DIR=\"/usr/lib\"' /usr/bin/firefox

Error:

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

I looked at char 22, but I don't see anything wrong. I know the problem has to do with the "", but I don't know how to escape them so that the shell interprets them the way I want.

Thanks for your help,

George
 
Old 07-21-2008, 09:52 AM   #2
maker10
LQ Newbie
 
Registered: Aug 2003
Posts: 15

Original Poster
Rep: Reputation: 0
Another problem with sed_2

Hi All,

I forgot to mention that the MOZ_LIB_DIR="/usr/lib64" is indented one space in the file.

Thanks,

George
 
Old 07-21-2008, 10:03 AM   #3
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
But in which file do you want to do the change? Not in /usr/bin/firefox I hope!

First, you do not have to use / in sed, you can use another marker:

sed 's/pat/pat2/'
can also be written
sed 's?pat?pat2?' or whatever

Because in your sed you didn't escape / in /usr/lib so sed takes it as the marker.

sed 's?MOZ_LIB_DIR="/usr/lib64"?#MOZ_LIB_DIR="/usr/lib64"\nMOZ_LIB_DIR="/usr/lib"?'

Last edited by nx5000; 07-21-2008 at 10:10 AM.
 
Old 07-21-2008, 10:31 AM   #4
maker10
LQ Newbie
 
Registered: Aug 2003
Posts: 15

Original Poster
Rep: Reputation: 0
Thanks

Thanks so much NX5000!

I had no idea that you could use other characters as markers when you use sed.
 
Old 07-21-2008, 10:51 AM   #5
nx5000
Senior Member
 
Registered: Sep 2005
Location: Out
Posts: 3,307

Rep: Reputation: 57
You're welcome

Here are some interesting documents about sed:

http://sed.sourceforge.net/
especially this one for a short introduction:
http://www-106.ibm.com/developerwork...ry/l-sed1.html
 
Old 07-21-2008, 11:54 AM   #6
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Mint
Posts: 17,809

Rep: Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743Reputation: 743
And.......

http://www.grymoire.com/Unix/Sed.html
 
Old 07-21-2008, 12:13 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 244Reputation: 244Reputation: 244
Code:
awk 'BEGIN{FS="="}
$1=="MOZ_LIB_DIR" && $2 ~ /\/usr\/lib64/{
 print "#"$0
 print $1 FS "/usr/lib";next
}1' file
 
  


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
problem using sed erin_0502 Programming 4 08-29-2007 03:01 AM
sed problem... jong357 Programming 11 05-09-2007 12:27 AM
Sed Problem Hydrap Linux - General 1 05-05-2006 03:25 AM
sed problem Warmduvet Programming 2 09-15-2004 06:33 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 10:38 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