This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sed: altered results in bash and cmd


fergus wrote:
To delete all lines beginning with a <space> in a text file, this
command (a) seems correctly composed and (b) works:

sed '/^ .*$/d' filename

but if I use it in a cmd window, the result is that all lines
_containing_ a space are deleted, not just those beginning with a space.

In general, and assuming PATHs etc correctly set, should not Cygwin
command lines work identically in bash and cmd windows? Is this a
problem with sed, with (my) command line syntax above, or with my
understanding of what should work when?

The difference in behaviour you are seeing results from the difference in the way cmd and bash interpret command lines and pass the resulting arguments to the specified commands.
Compare:


C:\>E:\cygwin\bin\echo.exe '/^ .*$/d'
/ .*$/d

C:\>

to:

mks ~
$ /cygdrive/e/cygwin/bin/echo.exe '/^ .*$/d'
/^ .*$/d

mks ~
$

As you can see, the '^' isn't passed to echo.exe by cmd. I'm not really sure but I think cmd doesn't treat single quotes as quoting characters - at least not in the way bash does.
If you use double quotes, it shout work in cmd:


C:\>E:\cygwin\bin\echo.exe "/^ .*$/d"
/^ .*$/d

C:\>

BTW: '/^ /d' shoud be enough to achieve what you are trying to.

Regards
  mks

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]