Search code examples
regexsvnseddiffcarriage-return

How to use regex expression (using sed) in windows using cygwin without removing carriage return?


I am currently using Cygwin in Windows. If I use sed to search and replace, carriage returns are removed since files are left with the unix touch of not having \r at the end of the lines.

This is a problem when using subversion, for example, since a file seems to have been changed completely if its carriage return lines are removed.

How can I use a regex expression, such as the following without effecting all my lines.

sed -i -e "s/SEARCH/REPLACE/g" `grep -rl SEARCH *`

Solution

  • The following does the job:

     sed -i -e "s/SEARCH/REPLACE/g;s/$/\\r/" `grep -rl SEARCH *`