sed: -e expression #1, char 8: unknown option to `s' | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

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

Shell Programming and Scripting


Tags
sed

Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 07-12-2012
ChickenPox ChickenPox is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 30 May 2014, 11:27 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
sed: -e expression #1, char 8: unknown option to `s'

Hello,
I need to replace a line in a file using sed. I have trying every which way I can think of but I continue to receive an error when I try. The error as you can see from my title line is :

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

Here is the line I am trying to run:

Code:
sed -r 's/\/dev\/shwr:MW:RK:s:e/\/dev\/shwr:AC:RK:s:e' myfile.txt

The file "myfile.txt" has a line it that looks like this:

Code:
/dev/shwr:MW:RK:s:e

and I need it to look like this:

Code:
/dev/shwr:AC:RK:s:e

Can someone tell me what I am doing wrong?

Thanks.

Last edited by Scrutinizer; 07-12-2012 at 05:01 PM.. Reason: code tags
Sponsored Links
    #2  
Old 07-12-2012
Vryali Vryali is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 29 August 2013, 3:54 PM EDT
Location: Columbia, SC
Posts: 64
Thanks: 19
Thanked 17 Times in 17 Posts
Quote:
sed: -e expression #1, char 8: unknown option to `s'

sed -r 's/\/dev\/shwr:MW:RK:s:e/\/dev\/shwr:AC:RK:s:e' myfile.txt
Guessing -r is a GNU option I'm not familiar with, so not sure what it's supposed to do. That aside:


Code:
sed 's/:MW:/:AC:/g' myfile.txt

works.

Edit: Pretty sure the only reason you're seeing an error is you didn't finish the syntax - you should have a / at the very end of your original statement at the very least.


Code:
sed 's/<findstr>/<replacestr>/<opt. flag>' <infile>


Last edited by Vryali; 07-12-2012 at 04:46 PM..
Sponsored Links
    #3  
Old 07-12-2012
ChickenPox ChickenPox is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 30 May 2014, 11:27 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Thanks Vryali. The problem is that "MW" is found in a bunch of places in my file. I really need it to only be changed on the line that begins with "/dev/shwr".
    #4  
Old 07-12-2012
Vryali Vryali is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 29 August 2013, 3:54 PM EDT
Location: Columbia, SC
Posts: 64
Thanks: 19
Thanked 17 Times in 17 Posts

Code:
$ echo /dev/shwr:MW:RK:s:e | sed 's=^/dev/shwr:MW:RK:s:e=/dev/shwr:AC:RK:s:e='
/dev/shwr:AC:RK:s:e

Two things then:

1. Use s= to change the delimter to make your life a little easier.
2. The point I'd mentioned before about your syntax is your actual fix

Edit: Cleaned up a bit - and also below is what you want per your stated requirements, I think


Code:
echo /dev/shwr:MW:RK:s:e | sed 's=\(^/dev/shwr.*\)\(:MW:\)\(.*$\)=\1:AC:\3='

Sponsored Links
    #5  
Old 07-13-2012
ChickenPox ChickenPox is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 30 May 2014, 11:27 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
My apologies, I forgot to type in some quotes on my original post. The line I am trying to update looks like this:

Code:
"/dev/shwr":MW:RK:s:e

Can I just escape the quotes?

---------- Post updated Jul 13th, 2012 at 07:48 AM ---------- Previous update was Jul 12th, 2012 at 02:56 PM ----------

Vryali,
thank you, I got it to work with out an error. One issue still exist though.

I'm taking this line:
/dev/shwr:MW:RK:s:e

And I want it to look like this line:
/dev/shwr:AC:RK:s:e

But it is putting a "g" at the next section like this:
/dev/shwr:AC:gRK:s:e

Some how it is reading the "g" in "\g='", I think. Can you help me with this?

Thanks so much.

---------- Post updated at 08:28 AM ---------- Previous update was at 07:48 AM ----------

Got it working....thanks so much.

Last edited by Franklin52; 07-12-2012 at 05:01 PM.. Reason: Please use code tags for data and code samples, thank you
Sponsored Links
    #6  
Old 07-13-2012
Vryali Vryali is offline
Registered User
 
Join Date: Jun 2008
Last Activity: 29 August 2013, 3:54 PM EDT
Location: Columbia, SC
Posts: 64
Thanks: 19
Thanked 17 Times in 17 Posts
Sorry for the lack of response, but it looks like you got it. Please post your final solution such that if someone else happens upon the thread they can see it as well.

Moderator's Comments:
edit by bakunin: Very good thinking! Alas, most people here just vanish after their problem is solved.

Last edited by bakunin; 07-13-2012 at 11:21 AM..
The Following User Says Thank You to Vryali For This Useful Post:
bakunin (07-13-2012)
Sponsored Links
    #7  
Old 07-13-2012
ChickenPox ChickenPox is offline
Registered User
 
Join Date: Jul 2012
Last Activity: 30 May 2014, 11:27 AM EDT
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
Yes, good thinking Vryali. Here is the line that I finally got to work for me:

echo "/dev/shwr":MW:RK:s:e | sed 's=\(^\"/dev/shwr\".*\)\(:MW:RK:\)=\1:AC:RK\:=' myfile.txt > mynewfile.txt
Sponsored Links
Closed Thread

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
awk error : invalid char '' in expression hael Shell Programming and Scripting 2 03-27-2012 06:51 AM
sed: -e expression #1, char 21: unterminated `s' command avinthm Shell Programming and Scripting 10 07-29-2011 09:00 AM
error: invalid conversion from ‘const char*’ to ‘char*’ GSO Programming 8 06-09-2011 01:39 PM
rpm -ba unknown option anand121 Linux 1 01-05-2011 04:27 AM
Adding a single char to a char pointer. pallak7 Programming 5 12-06-2008 11:46 PM



All times are GMT -4. The time now is 02:32 PM.