Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Lately I've been needing to delete new untracked files from my versioning system. Being in linux I use:

hg status -un|xargs rm

And it works nice, but when doing it in windows, hg status lists paths with backslash so that is where stuff goes wrong. So then I try:

hg status -un|sed 's/\\/\//g'

...but I get the error: sed: -e expression #1, char 8: unterminated `s' command

Then I try some ascii:

`hg status -un|sed 's/\o134/\o57/g'` 

...that gets me: sed: -e expression #1, char 14: Trailing backslash

And some scripting:

hg status -un|sed 's/`echo \`/`echo /`/g'

...that gets me: sed: -e expression #1, char 19: unknown option to `s'

I try all the last with any other characters and I get the expected output... so I'm completely lost. I have cygwin, of course, and I want to avoid using a file (that is what I've been doing).

Thanks in advance

share|improve this question
up vote 1 down vote accepted

duke!, you are doing it wrong!, you can use : instead of / for the regex:

hg status -un|sed 's:\\:/:g'


share|improve this answer

To avoid the 'Trailing backslash' error you should make sure you don't remove the last backslash. this can be done by ensuring in the regex that another 'non'backslash character always follows the character being replaced. the sed should look like this...

sed "s:\\([^\]\+\):/\1:g"

.. which roughly translates as:

find a backslash, followed by at least 1 character that is not a backslash, and replace with a forward slash followed by the other matched characters.

Note that in my regex (for bash) I didn't need to escape the backslashes, but i needed to escape the round braces. The '\1' is a back reference.

Hope that makes sense!

share|improve this answer

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .