bmatzelle / gow

Unix command line utilities installer for Windows.
https://github.com/bmatzelle/gow/wiki
6.55k stars 363 forks source link

sed with path translations issue? #246

Open arteika opened 6 years ago

arteika commented 6 years ago

I am parsing a bunch of http urls using bash, sed, and awk in GOW. I am trying to filter out some of the lines with sed but get an error:

echo "g.jar" | sed -n -e '/[0-9].jar/p'
sed.exe: -e expression #1, char 1: unknown command: `C'

$ echo "000.jar" | sed -n -e '/a/p'
sed.exe: -e expression #1, char 1: unknown command: `C'

echo "000.jar" | sed -n -e "/a/p"
sed.exe: -e expression #1, char 1: unknown command: `C'

in GOW. In cygwin, I get a correct result:

$ echo "000.jar" | sed -n -e '/[0-9].jar/p'
000.jar

$ echo "g.jar" | sed -n -e '/[0-9].jar/p'
oldpink commented 3 years ago

I don't know how to correct this issue permanently, but you will find that your problem is not with the version of sed packaged wiht GOW itself, but with the shell bash.exe instead. I was hoping to use this shell with my scripts that extensively call sed that use the "/" as the default sed delimiter, but I was only able to overcome this issue by using a different delimiter instead, i.e. in your script above that calls as follows: sed -n -e '/[0-9].jar/p' Changed to this: sed -n -e '\%[0-9].jar%p' Note that you can use whatever delimiter you like with sed commands that start with the delimiter, but when using the alternate delimiter, you must use a leading "\" immediately before the delimiter to get it to work. Of course, if you use the type of sed command that has a leading command, you don't need the leading backslash: e.g. "sed 's/TEST/test/'" can be safely rewritten as "sed 's%TEST%test%'" If you or anyone else can find a way to make the "/" as the default delimiter with the GOW shell, please reply here, though.