Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I am attempting to use SED for the first time. To complicate matters, i am using it in windows. I downloaded from this source. Since I don't have install privileges on my work machine I created a folder in my profile for executables and added it to my PATH .

I am having issues try to use SED for the first time. It keeps failing with the error:

sed: -e expression #1, char 1: unknown command: `'' I have tried a few different samples from This how to but I just can't get it. I found none else is having this problem. What should I try? I have tried encapsulating it in quotes, double quotes and back-quotes. Nothing seems to help.

share|improve this question
    
What exactly are you running? –  johnny Feb 15 '12 at 16:08
    
I would highly recommend cygwin, the windows shell is such a PITA for unix-like commands. However, if you are planning on sticking with the windows shell, the easiest way ive found to run sed or awk is by creating a script file and then calling the file with the -f flag. For example sed -f some_sed_script.sed or awk -f some_awk_script.awk –  SiegeX Feb 15 '12 at 17:10
    
Can you paste exactly what you're giving to the windows shell? –  Rob Feb 15 '12 at 17:17
    
I thought I did include my input. I wish i did, because now it works after I tried @RedGrittyBrick gave –  TheSavo Feb 15 '12 at 18:09

2 Answers 2

up vote 2 down vote accepted
C:\>sed sdf
sed: -e expression #1, char 3: Unterminated `s' command

C:\>echo aaa > f
C:\>sed -e "s/a/x/" < f
xaa

This is using sed from unxutils

share|improve this answer
    
This worked!. thank you. Is is that because the -e parameter ? –  TheSavo Feb 15 '12 at 18:00
    
Not sure what was wrong, removing the -e parameter and the double " quotes, it still works –  TheSavo Feb 15 '12 at 18:10

Unlike the Unixes, the Windows command-line shell does not perform any word-splitting and does not strip away the quotes; the program just receives a single string containing the entire command line. This means that not all programs can follow the same quoting rules.

In this case, the GnuWin32 version of sed only supports one quoting style – " double quotes ". For example, in my tests the following works fine:

sed "s/foo/bar/"

You can also get sed from Cygwin, along with a more-complete Unix-like system: shells, editors, other tools. It will be easier if you use a Unix shell for learning, to avoid such syntax issues in the future.

share|improve this answer
    
beat my cygwin comment by seconds... :) –  Rich Homolka Feb 15 '12 at 15:40
    
thanks. Does CygWin offer a non install? I tried with " double quotes and still no joy. –  TheSavo Feb 15 '12 at 16:05
    
@TheSavo just delete the directory. there are some registry entries related to cygwin mounts, but these can be safely ignored, only cygwin reads them –  Rich Homolka Feb 28 '12 at 6:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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