delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2004/08/21/20:38:33

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Date: Sat, 21 Aug 2004 20:05:34 -0400
From: "Pierre A. Humblet" <pierre DOT humblet AT ieee DOT org>
To: cygwin AT cygwin DOT com
Subject: Re: grep: $ in PATTERN doesn't seem to work properly
Message-ID: <20040822000534.GA1110049@hpn5170>
References: <NGBBLLIAMFLGJEOAJCCEEEDPDNAA DOT _garbage_collector_ AT telia DOT com> <Pine DOT GSO DOT 4 DOT 61 DOT 0408211845500 DOT 19750 AT slinky DOT cs DOT nyu DOT edu>
Mime-Version: 1.0
In-Reply-To: <Pine.GSO.4.61.0408211845500.19750@slinky.cs.nyu.edu>
User-Agent: Mutt/1.4.1i
Resent-From: "Pierre A. Humblet" <pierre DOT humblet AT ieee DOT org>
Resent-Date: Sat, 21 Aug 2004 20:34:15 -0400
Resent-To: cygwin AT cygwin DOT com
Resent-Message-Id: <EI2TO93-00AF6H-MS AT hpn5170>

On Sat, Aug 21, 2004 at 07:07:21PM -0400, Igor Pechtchanski wrote:
> On Sat, 21 Aug 2004, Hannu E K Nevalainen wrote:
> 
> > Note that there is a difference depending on how you create the file; I'll
> > hand over to cygwin-specialists to explain (or ponder on) why it has to be
> > this way.
> > 
> > I'm running BINARY mounts all over, still I get the behaviour below.
> > [snip]
> > === a) ===
> > $ cd			# cd to $HOME
> > $ cat >tmp
> > Line 1
> > Line 2
> > 
> > Line 3
> > Line 4
> > Line 5
> > $POSIX="" - Hannu AT P450 ~ bash (P)PID=(852)2340, s=0
> > $ od -w8 -t x1z tmp
> > 0000000 4c 69 6e 65 20 31 0d 0a  >Line 1..<
> > 0000010 4c 69 6e 65 20 32 0d 0a  >Line 2..<
> > 0000020 0d 0a 4c 69 6e 65 20 33  >..Line 3<
> > 0000030 0d 0a 4c 69 6e 65 20 34  >..Line 4<
> > 0000040 0d 0a 4c 69 6e 65 20 35  >..Line 5<
> > 0000050 0d 0a                    >..<
> > 0000052
> > $ grep '1$' tmp
> > $ d2u tmp 				# dos2unix
> > tmp: done.
> > $ grep '1$' tmp
> > Line 1
> > 
> > === b) ===
> > $ cd
> > $ ls -l tmp2
> > ls: tmp2: No such file or directory
> > $ for (( i=1 ; i<6 ; i++ )) do echo >>tmp2 "Line $i";done
> > $ od -w7 -t x1z tmp2
> > 0000000 4c 69 6e 65 20 31 0a  >Line 1.<
> > 0000007 4c 69 6e 65 20 32 0a  >Line 2.<
> > 0000016 4c 69 6e 65 20 33 0a  >Line 3.<
> > 0000025 4c 69 6e 65 20 34 0a  >Line 4.<
> > 0000034 4c 69 6e 65 20 35 0a  >Line 5.<
> > 0000043
> > $ grep '1$' tmp
> > Line 1
> > 
> > $ rm tmp tmp2
> 
> This has to do with the way "cat" behaves.  By default, Windows sends 
> textmode line endings from the console.  Most applications (including od, 
> echo, bash, etc) compensate for this somehow, except "cat", which *always* 
> replicates the output character by character, doing no processing 
> *whatsoever*.  AFAIK, this is by design.
> 
> Case in point:
> 
> $ od -c
> <Enter><Ctrl-D>
> 0000000  \n
> 0000001
> $ cat | od -c
> <Enter><Ctrl-D>
> 0000000  \r  \n
> 0000002
> $ perl -pe 1 | od -c
> <Enter><Ctrl-D>
> 0000000  \n
> 0000001
> $ # Note, however:
> $ perl -pe 1 | cat | od -c
> <Enter><Ctrl-D>
> 0000000  \n
> 0000001
> $ 

See also <http://www.cygwin.com/ml/cygwin/2003-04/msg02268.html>
I once sent a patch to a transient coreutils maintainer but
there was no followup.

Pierre

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019