Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

'sed' for DOS - behaviour

Options
  • 09-01-2007 5:53pm
    #1
    Closed Accounts Posts: 2,349 ✭✭✭


    I'm learning to use sed and I'm using the DOS version. Simple commands like
    echo "123 abc" | sed 's/[0-9]*/&> &/'
    

    work fine under my linux shell account but in does just gives an error like "& not expected at this point".

    What can I do?


Comments

  • Registered Users Posts: 6,509 ✭✭✭daymobrew


    I recommend installing Cygwin. It includes tons of Unix programs ported to work under Windows (in DOS/Command Prompt shell). You reference drives like '/cygdrive/c/WINNT'. And the command you quote will probably work without issues.

    Download the tiny Cygwin installer and then run it to install bash, sed and all the other utilities that you want.


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    Sound out


  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    For Unix, it's fine to do
    echo "123 abc" | sed 's/[0-9]*/&> &/'

    However, DOS interprets the quotes and apostrophes in a different way. To do this in DOS, simply change the way you're doing it to:

    echo 123 abc | sed "s/[0-9]*/&> &/"


  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    I've tried both ways, also tried reading from files etc.


  • Moderators, Recreation & Hobbies Moderators, Science, Health & Environment Moderators, Technology & Internet Moderators Posts: 91,693 Mod ✭✭✭✭Capt'n Midnight


    Oh don't get me started on microsoft's command processor and trying to pass special characters like " & <> in batch files

    deffo recommend cygwin
    BTW
    in nt-2003 most of the time / can be used as directory separator instead of \

    http://www.microsoft.com/resources/documentation/windows/xp/all/proddocs/en-us/ntcmds_shelloverview.mspx?mfr=true
    & [...] command1 & command2
    Use to separate multiple commands on one command line. Cmd.exe runs the first command, and then the second command.

    && [...] command1 && command2
    Use to run the command following && only if the command preceding the symbol is successful. Cmd.exe runs the first command, and then runs the second command only if the first command completed successfully.



    The ampersand (&), pipe (|), and parentheses ( ) are special characters that must be preceded by the escape character (^) or quotation marks when you pass them as arguments.


    http://www.grymoire.com/Unix/Sed.html#uh-2
    The character after the s is the delimiter. It is conventionally a slash, because this is what ed, more, and vi use. It can be anything you want, however.
    ...
    Some people use commas, others use the "|" character. Pick one you like. As long as it's not in the string you are looking for, anything goes.


    if you can get all references to & inbetween a set of " then it may ignore them

    http://www.grymoire.com/Unix/Sed.html#uh-10
    try dumping >
    and instead you can specify a file that will receive the modified data.


  • Advertisement
  • Closed Accounts Posts: 2,349 ✭✭✭nobodythere


    Not worth the effort, I just got cygwin, works well


Advertisement