Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com Message-ID: <5D139685F337FC44A97D330F8F1BF6FA07DEF3@MORSE> From: "Dalton, Barnaby" To: "'cygwin AT cygwin DOT com'" Subject: RE: Grep and matching end of line (anchoring) Date: Mon, 22 Nov 2004 10:15:01 -0000 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-IsSubscribed: yes Thanks for all the replies. In practice I am using grep on the output of a DOS utility rather than via cat (sorry for the bad example). So I was originally writing something like: doscommand | grep '\.h$' I imagine its fairly common usage to want to pipe DOS command output to cygwin utilities. Although its pretty simple to use perl/sed/tr filer in the middle it would be nice if cygwin came with a script that did this so that I could write something like: doscommand | dos2unix | grep '\.h$' I just typed 'dos2unix' on the command line and discovered that it already exists in cygwin and does exactly what I need! So my problem is already solved :-) Barney $ dos2unix --help dos2unix version 0.1.2 converts the line endings of text files from DOS style (0x0d 0x0a) to UNIX style (0x0a) Usage: dos2unix [OPTION...] [input file list...] Main options (not all may apply) -A, --auto Output format will be the opposite of the autodetected source format -D, --u2d Output will be in DOS format --unix2dos Output will be in DOS format -U, --d2u[=2] Output will be in UNIX format --dos2unix[=2] Output will be in UNIX format Help options -?, --help Show this help message --usage Display brief usage message --version Display version information --license Display licensing information Other arguments [input file list...] for each file listed, convert in place. If none specified, then use stdin/stdout > -----Original Message----- > From: Buchbinder, Barry (NIH/NIAID) [mailto:BBuchbinder AT niaid DOT nih DOT gov] > Sent: 19 November 2004 15:17 > To: 'cygwin AT cygwin DOT com' > Subject: RE: Grep and matching end of line (anchoring) > > > At Friday, November 19, 2004 7:41 AM, Reini Urban wrote: > > Dalton, Barnaby schrieb: > >> I'm having trouble getting grep to match end of line when used with > >> files/utilities that use DOS linefeeds. For example: > >> > >> cat files.txt | grep '\.h$' > >> > >> produces no output. However, if I stick a filter in the middle to > >> change the line endings: > >> > >> cat files.txt | perl -pe 's/\r\n/\n/' | grep '\.h$' > >> I get: > >> > >> file1.h > >> file2.h > >> > >> as expected. > > > > pipes are treated as binmode, so they don't convert eol from \r\n to > > \n. without pipe it should work on a textmount: > > > > grep '\.h$' files.txt > > or grep '\.h$' < files.txt > > > >> Should grep's $ match \r\n or should I expect to have to > convert line > >> endings? > > > > grep's "$" is not expected to do textmode magic if stdin is binmode. > > > > BTW: > > cat files.txt | sed 's,\r\n,\n,' | grep '\.h$' > > is simpler. > > > > Someone might think of a new textmode pipe operator (like a > new "t|"), > > but I don't consider that a good idea. > > man bash /REDIRECTION and /Pipelines > > -- > > Reini Urban > > http://xarch.tu-graz.ac.at/home/rurban/ > > Assuming that \r never occurs in the middle of a line: > cat files.txt | tr -d '\r' | grep '\.h$' > > This should work whether or not one is on a text mount or for > the file has > DOS or Unix line endings: > cat files.txt | grep -E '\.h^M?$' > > -- > 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/ > ********************************************************************** This email and any files transmitted with it are confidential and intended solely for the use of the individual or entity to whom they are addressed. If you have received this email in error please notify postmaster AT radioscape DOT com. This footnote also confirms that this email message has been scanned for the presence of computer viruses known at the time of sending. www.radioscape.com ********************************************************************** -- 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/