public inbox for cygwin@cygwin.com
 help / color / mirror / Atom feed
* Grep can't match characters before EOL marker without ^M
@ 2018-01-03 17:31 David Karr
  2018-01-03 17:56 ` Brian Inglis
  2018-01-03 18:45 ` arrl via cygwin
  0 siblings, 2 replies; 4+ messages in thread
From: David Karr @ 2018-01-03 17:31 UTC (permalink / raw)
  To: The Cygwin Mailing List

My cygwin version appears to be "2.9.0(0.318/5/3)".

If I have a text file that has a line that ends with "abc", and I try
to grep for "abc$", it doesn't match.  I find that it does match "$"
and "abc^M$".

I've read some of the documentation about line endings in Cygwin.

I need to write some scripting that works on both Cygwin and Linux.
What do I need to do here?

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Grep can't match characters before EOL marker without ^M
  2018-01-03 17:31 Grep can't match characters before EOL marker without ^M David Karr
@ 2018-01-03 17:56 ` Brian Inglis
  2018-01-03 18:45 ` arrl via cygwin
  1 sibling, 0 replies; 4+ messages in thread
From: Brian Inglis @ 2018-01-03 17:56 UTC (permalink / raw)
  To: cygwin

On 2018-01-03 10:31, David Karr wrote:
> If I have a text file that has a line that ends with "abc", and I try to grep
> for "abc$", it doesn't match. I find that it does match "$" and "abc^M$".
> I've read some of the documentation about line endings in Cygwin.
> I need to write some scripting that works on both Cygwin and Linux.
> What do I need to do here?

Use grep '...[[:cntrl:]]\?$' to match, d2u|dos2unix or sed 's/\r$//' to remove.

-- 
Take care. Thanks, Brian Inglis, Calgary, Alberta, Canada

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Grep can't match characters before EOL marker without ^M
  2018-01-03 17:31 Grep can't match characters before EOL marker without ^M David Karr
  2018-01-03 17:56 ` Brian Inglis
@ 2018-01-03 18:45 ` arrl via cygwin
  2018-01-04 19:51   ` cyg Simple
  1 sibling, 1 reply; 4+ messages in thread
From: arrl via cygwin @ 2018-01-03 18:45 UTC (permalink / raw)
  To: cygwin

On 1/3/2018 12:31 PM, David Karr wrote:
> My cygwin version appears to be "2.9.0(0.318/5/3)".
> 
> If I have a text file that has a line that ends with "abc", and I try
> to grep for "abc$", it doesn't match.  I find that it does match "$"
> and "abc^M$".
> 
> I've read some of the documentation about line endings in Cygwin.
> 
> I need to write some scripting that works on both Cygwin and Linux.
> What do I need to do here?
> 

Consider running dos2unix on files containing ^M at line ends.


-- 
Tim Prince

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: Grep can't match characters before EOL marker without ^M
  2018-01-03 18:45 ` arrl via cygwin
@ 2018-01-04 19:51   ` cyg Simple
  0 siblings, 0 replies; 4+ messages in thread
From: cyg Simple @ 2018-01-04 19:51 UTC (permalink / raw)
  To: cygwin

On 1/3/2018 1:39 PM, arrl via cygwin wrote:
> On 1/3/2018 12:31 PM, David Karr wrote:
>> My cygwin version appears to be "2.9.0(0.318/5/3)".
>>
>> If I have a text file that has a line that ends with "abc", and I try
>> to grep for "abc$", it doesn't match.  I find that it does match "$"
>> and "abc^M$".
>>
>> I've read some of the documentation about line endings in Cygwin.
>>
>> I need to write some scripting that works on both Cygwin and Linux.
>> What do I need to do here?
>>
> 
> Consider running dos2unix on files containing ^M at line ends.
> 

You might wish to test for a binary file before running dos2unix on it
though or even using sed to substitute ^M$ to remove them.  Binary data
could contain a CRLF that would destroy the binary file if CR is removed.

Also consider doing the same instruction regardless of the OS because
you never know when your script meets a file from a different OS. In the
business world many people send files from Windows to *NIX and vice
versa.  If a text file from *NIX is sent to a user of Windows be sure
that the file contains the appropriate CRLF or the user will just see
garbage unless they are a DevOPS person who knows how to deal with the
file.  I can't count the number of times I've had to resend a file or
help someone adjust one just because the Windows default for .txt files
is Notepad which uses the CR to advance to the next line of the GUI.

-- 
cyg Simple

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

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2018-01-04 19:51 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-01-03 17:31 Grep can't match characters before EOL marker without ^M David Karr
2018-01-03 17:56 ` Brian Inglis
2018-01-03 18:45 ` arrl via cygwin
2018-01-04 19:51   ` cyg Simple

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).