Sed for windows
Solution 1
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
Solution 2
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.
Solution 3
Appreciate this is an old question however if you have Git Bash installed you can use a lot of unix features (sed /ssh / scp/ grep) in a Windows environment.
TheSavo
I am a systems administrator in Albany, NY. I have been around computers for the last 20 years. I have a Bachelor's degree in computer network administration. I have a very broad skill set in computer administration. I have supported networks of 50 - 200 users. I have many hobbies in the computer arena, which includes the following: Debian Linux Package Server mirroring and caching. This is used for installing new Debian systems, and providing local system updates to existing Debian Linux systems. Basic LaTeX typesetting of documents. Recently I have started to learn desktop typesetting using the TeX (LaTex) programming architecture. I have built 3 Workflow programs. For managing and maintaining users information for the data systems that I have to support.
Updated on September 18, 2022Comments
-
TheSavo over 1 year
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 installation privileges on my work machine, I created a folder in my profile for executables and added it to my
PATH
.I am having issues trying 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 noone 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.
-
johnny about 12 yearsWhat exactly are you running?
-
Rob about 12 yearsCan you paste exactly what you're giving to the windows shell?
-
TheSavo about 12 yearsI thought I did include my input. I wish i did, because now it works after I tried @RedGrittyBrick gave
-
-
Rich Homolka about 12 yearsbeat my cygwin comment by seconds... :)
-
TheSavo about 12 yearsthanks. Does CygWin offer a non install? I tried with
"
double quotes and still no joy. -
TheSavo about 12 yearsThis worked!. thank you. Is is that because the
-e
parameter ? -
TheSavo about 12 yearsNot sure what was wrong, removing the
-e
parameter and the double"
quotes, it still works