This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Additional carriage return added by cygwin commands to DOS text files

ttjqryfbndgdx wrote:
I know it's a common issue, but I didn't find a solution to my problem in the

I have a "dos" file (lines ends with carriage return+line feed : 0d0a in Hex) :
bash-3.2$ xxd test1
0000000: 6161 610d 0a62 6262 0d0a                 aaa..bbb..

If I apply a cygwin command to this file, I get an additional carriage return :
bash-3.2$ grep -E 'a|b' test1 > test2
bash-3.2$ xxd test2
0000000: 6161 610d 0d0a 6262 620d 0d0a            aaa...bbb...

I chose dos mode when installing cygwin.
My filesystems are mounted "textmode"

It seems that grep always opens the file in binary mode, so it ignores the Cygwin mount mode.

      while ((desc = open (file, O_RDONLY)) < 0 && errno == EINTR)

Moreover, I see in the same source that grep has an "undossify" feature:

  if (fillsize)
    fillsize = undossify_input (readbuf, fillsize);

But it may be disabled in Cygwin.

I experienced the same issue with the "cat" command, and unfortunately I didn't find any transparent solution :-(

Cygwin's text mode handling is great, but some UNIX utilities like cat and grep are designed to act on either binary or text files, so they always open the files in binary mode, and we get that additional CR issue.

Vincent Rivière

Problem reports:
Unsubscribe info:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]