cygwin - sed/awk: DOS to UNIX path substitution within a file -


I have a file that includes paths like this:

  C: \ Bad \ Foo.c C: \ good \ foo.c C: \ good \ bar \ foo.c C: \ good \ bar \ [variable subdir count] \ foo.c  

And I would like to get the following file:

  c: \ bad \ foo.c C: /good/foo.c C: /good/bar/foo.c C: / Good / Bar / [variable subdir count] /foo.c  

Note that non-matching paths should not be modified.

I know how to do this with a sed for a certain number of subdir, but a variable number is giving me trouble. Actually, I have several S / X / Y / expressions (maximum depth In the form ... not very gorgeous) will have to be used.

May be with awk, but such magic is beyond my skill.

FYI, I need this trick to fix some gcov binary files on a cygwin platform.


Edit: There is a point on which I have not given enough strength; I am working with binary files; Therefore, I may have the following types of data:

  bindata \ bindata% bindataC: \ good \ foo.c  

that should be translated: The first / should not be translated, disgusts that it is in the same line.

However, when I edit this text, I simply check my .gcno files and it seems that all paths are flanked with zero, so the most answers given below should be fit.

Thank you!

  sed -e '/ ^ c: \\ good / s / \\ / \ // g 'input_file.txt  

Comments