Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
add comment

2 Answers

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'

*facepalm*

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.