[GLLUG] SED Emergency

C. Ulrich dincht@securenym.net
Mon, 12 May 2003 11:35:02 -0400


Brian Hoort wrote:
> I suspect this has something to do with the version of sed I'm using not
> being able to handle DOS ANSI text from the batch file properly, and it
> is misinterpreting the '>' character, or something along those lines.
> Please note that I've used this method in the lab before, had the same
> problem, but somehow got around it by removing the spaces around the '>'
> in the following command (this command is one, long line):

I don't know if I follow the complete problem (haven't used sed much), but I'd
like to take a stab at it since I'm a bit bored at the moment. :) Okay, so you
have the command:

sed.exe "s\gradsetup\%USERNAME%\g" registry.dat >registry.new

In regards to the extra 1, it shouldn't be hurting anything. I don't know
where it's being inserted but under both bash and WinXP, "1>" means "pipe
stdout to file" and "2>" means "pipe stderr to file". However... I'm assuming
that everything after "registry.dat" should be interpreted by the shell rather
than sed, but it looks like maybe sed is getting it instead (hence the "extra
characters"). Strange. Seems like I've seen this before in DOS, but I can't
remember how to fix it.

A quick search turned up a mailing list post
(http://mail.gnu.org/archive/html/bug-gnu-utils/2001-01/msg00185.html) which
says that it's normally not a good idea to try to use sed with binary files on
non-Unix systems. My recommendation: find a tool that will allow you to modify
the registry from the commandline rather than forcing Unix text tools to
mangle Windows binary files. :) There should be programs available somewhere
that can modify the registry from within a script, it wouldn't even surprise
me if one ships with some versions of Windows. If you're handy with C/C++ and
Windows development, a tiny .exe might do the trick. Visual Basic is quite
nice for automating things in Windows (er, sometimes). I believe Perl, Python,
and Tcl have extensions that will let you modify the registry too.

Good luck.

--Charles Ulrich
-- 
http://bityard.net