2

Q. I want to write a 2 line program that lets me substitute "the" with "zee" and "The" with "Zee".

Here is what I'm doing:

I'm writing a sed program for example, program.sed. Inside it, I'm writing

s/the/zee/ \\
The/Zee/g  

Then I'm running program.sed like this

sed -f program.sed otherfilename       

ERROR:

Unfortunately, error occurs, saying command garbled: s/the/zee/g

NOTE: If I do change text c\\ in sed with any other commands etc. it works fine, but the problem is with substitution like for example in the above question.

EDIT:

The down solution worked for me the first one before Or, but not the second one. Maybe because the gator version is pretty old. "Oracle Corporation SunOS 5.10 Generic Patch January 2005". sed version is very old also "23 July 1998". Just wanted others know.

6
  • @don_crissti, before posting here I even tried that, but it gives the same error.
    – Anonymous
    Jul 22 '16 at 9:27
  • 1
    @GhostRider which sed version are you using? I tried @don_crissti's suggestion on sed (GNU sed) 4.2.2 and it worked fine
    – Sundeep
    Jul 22 '16 at 9:31
  • In your note, you mention using c\\ , but your example code only contains \\ . Which is correct, and what do you think that should do? Jul 22 '16 at 9:58
  • @GhostRider which sed version are you using? I can not see how you get that error for that input. (s/the/zee/g does not appear in input) Jul 22 '16 at 10:09
  • 1
    do add that info in your question so that it is useful for users visiting this thread.. also add the output of sed --version if it is available (or perhaps available in man sed
    – Sundeep
    Jul 22 '16 at 16:42
4

In your program.sed you should have:

s/the/zee/g; s/The/Zee/g

Or:

s/the/zee/g
s/The/Zee/g
3
  • @StéphaneChazelas thanks for completing my answer mate. I appreciate.
    – user172564
    Jul 22 '16 at 9:51
  • 1
    The first solution above Or worked for me, but the second one did not. Just wanted other's know. Thanks a lot.
    – Anonymous
    Jul 22 '16 at 16:47
  • 1
    @GhostRider My pleasure mate. Thanks for letting us know.
    – user172564
    Jul 22 '16 at 16:49

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.