Discussion:
Probleming using gnu sed in windows batch script
'Ben Stover' bxstover@yahoo.co.uk [sed-users]
2014-09-28 07:55:57 UTC
Permalink
I want to use gnu sed for windows (available here: http://gnuwin32.sourceforge.net/packages/sed.htm)
to replace some bytes in file test.txt by other bytes.


Therefore I created (on 64bit Windows 7) the following DOS batch script:


echo start
sed 's/\xc3\xbc/\xtc/g' <test.txt >testnew.txt
pause




However when I run this batch script by double clicking I got the following error:


sed: -e expression #1, char 1: unknown command: `''


Why?


Thank you
Ben
zharif@arcor.de [sed-users]
2014-09-28 12:26:28 UTC
Permalink
try

sed "s/\xc3\xbc/\xtc/g" "test.txt" > "testnew.txt"

Zharif
Post by 'Ben Stover' ***@yahoo.co.uk [sed-users]
I want to use gnu sed for windows (available here: http://gnuwin32.sourceforge.net/packages/sed.htm)
to replace some bytes in file test.txt by other bytes.
echo start
sed 's/\xc3\xbc/\xtc/g' <test.txt >testnew.txt
pause
sed: -e expression #1, char 1: unknown command: `''
Why?
Thank you
Ben
------------------------------------
------------------------------------
Jim Hill gjthill@gmail.com [sed-users]
2014-09-28 17:59:26 UTC
Permalink
Are you perhaps having character-set problems? Windows software often
defaults to UTF-16, which at the OS / ops & admin layer is simply
unworkable from a backwards-compatibility standpoint for unix-based
systems. You want to be sure you're saving as UTF-8 or lower, ascii
would do for this
zharif@arcor.de [sed-users]
2014-09-28 18:47:48 UTC
Permalink
Just a little bit more information.

Microsofts command line syntax require the use of surrounding doublequotes for any sed command. This is also true when using batch files. Single quotes are not accepted and lead to the sed error output posted by Ben.
Furthermore any path or filename should be surrounded by doublequotes. Although this is not mandatory for file or pathnames that doesn't contain spaces, its a good and secure coding behaviour to do so.
If you refer to a file and try to redirect output to another file the correct and commonly used syntax is posted below.
the command "start" opens a new command line instance and provides additional options. I guess you don't want to use it here.

@echo on
start sed "s/\xc3\xbc/\xtc/g" "test.txt" > "testnew.txt"
:: this should also work - remove both colons to try
:: sed "s/\xc3\xbc/\xtc/g" "test.txt" > "testnew.txt"
pause

Zharif

[Non-text portions of this message have been removed]
'Ruud H.G. van Tol' rvtol@isolution.nl [sed-users]
2014-09-28 19:13:52 UTC
Permalink
Post by 'Ben Stover' ***@yahoo.co.uk [sed-users]
I want to use gnu sed for windows (available here: http://gnuwin32.sourceforge.net/packages/sed.htm)
to replace some bytes in file test.txt by other bytes.
echo start
sed 's/\xc3\xbc/\xtc/g' <test.txt >testnew.txt
pause
sed: -e expression #1, char 1: unknown command: `''
Why?
Hello Ben,

As was said, switch to proper Windows command line quotes.

Alternatively, create a file "utf8-to-latin1.sed" and use that.

(or use a specialized tool for that transformation;
instead of "\xtc" you probably meant "\xFC")
--
Greetings, Ruud
Loading...