Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Stop sed on windows from changing \r to \r\n

Tags:

windows

sed

I'm using sed on windows to delete some superfluous lines in a unix style format (\n line endings). Unfortunately, sed replaces these line endings even in lines it does not change to \r\n. How can I stop sed from doing that?

My sed is a simple sed-for-windows-standalone-exe:

C:\dev>sed --version
super-sed version 3.59
based on GNU sed version 3.02.80
like image 521
mort Avatar asked Aug 08 '11 14:08

mort


2 Answers

GNU sed ( http://gnuwin32.sourceforge.net/packages/sed.htm ) has the -b option for "binary mode", i. e. not replacing \n with \r\n.

If you use the sed that comes with cygwin then it usually uses the binary mode even without the -b option. Namely, cygwin commands use the input file path to decide whether they should run in text or binary mode, i. e. outputting \r\n or \n: http://www.cygwin.com/cygwin-ug-net/using-textbinary.html. As the document says, binary mode is the default for MS-DOS pathnames, and in my experience the filesystems mounted by default are also mounted in binary mode.

like image 179
Jaan Avatar answered Sep 18 '22 12:09

Jaan


If you add the parameter -b you treat the file as a binary file and it won't change your line endings. The manual states:

 -b, --binary

          open files in binary mode (CR+LFs are not processed specially)
like image 33
Kokkie Avatar answered Sep 20 '22 12:09

Kokkie