Operating System - Linux
1753464 Members
4933 Online
108794 Solutions
New Discussion

Can't get sed to replace string with semicolon.

 
SOLVED
Go to solution
Fred Abell
Occasional Advisor

Can't get sed to replace string with semicolon.

I am writing a bash script. In the file /etc/samba/smb.conf, I wish to substitute the string:

 

;       realm = MY_REALM

 

with the string:

 

        realm = GROUP.COM

 

notice the semicolon is gone.

 

SED sees the semicolon as special, and I don't know AWK. Anyone got a one liner:

 

Thanks again to all who respond to my questions regularly,

 

 

To describe my problem in fuller detail as suggested, the command:

 

sed -i 's/";       realm = MY_REALM"/"        realm = GROUP.COM"/g' /etc/samba/smb.conf

 

has issues with the semicolon.

4 REPLIES 4
Steven Schweda
Honored Contributor

Re: Can't get sed to replace string with semicolon.

 
H.Becker
Honored Contributor
Solution

Re: Can't get sed to replace string with semicolon.

>>> has issues with the semicolon.

 

Maybe, but not in this example. And a semicolon may be special for a shell, but it looks like it is already escaped so that the shell should leave it alone. The quoting you use, asks sed to look for a double quoted string to be replaced by another double quoted string. I don't think you have such quoted strings in the file. So
 
sed -i 's/;       realm = MY_REALM/        realm = GROUP.COM/g' /etc/samba/smb.conf
 
should do.
Steven Schweda
Honored Contributor

Re: Can't get sed to replace string with semicolon.

 
Dennis Handly
Acclaimed Contributor

Re: Can't get sed to replace string with semicolon.

>has issues with the semicolon.

 

As Steven said, you have issues with whitespace, not semicolon.