procmail
[Top] [All Lists]

Re: Ways to check for CRLF? (Was: Error???)

2003-06-13 09:36:28
Date: Fri, 13 Jun 2003 10:14:46 -0400
From: Jason Tishler <jason(_at_)tishler(_dot_)net>

What about od piped through fgrep?

    $ od -c crlf | fgrep '\r'
    0000000   h   e   l   l   o  \r  \n   b   y   e  \r  \n

    $ od -c lf | fgrep '\r'
    $

Or, just fgrep if you are willing to deal with explaining how to enter a
"^M" to the shell:

This is accomplished in bash and the version of pdksh I use by typing
    ^V^M
both characters being the control characters entered by typing them
into the keyboard. ^V escapes the shell's input and allows a literal
control character to be entered. I would put them into single quotes as
you have below. Without quotes, you're venturing into POSIX "undefined
behavior" territory. I can't speak for any of the other shells.


    $ fgrep '^M' crlf 
    hello
    bye

    $ fgrep '^M' lf
    $

Jason

I'd assume rather than simply detecting these retarded carriage returns,
one would like to remove them.
Assume "crlf" is your file containing the carriage returns (DOS-style) and
"lf" is the output file to contain no carriage returns (UNIX-style).

    $ sed 's/^M$//' < crlf > lf

This uses the ^V^M trick I mentioned above. It's very important that the
two files are different filenames, else you'll overwrite your recipe stuff.
At the risk of turning this into a sed-users list, this is a commonly asked
question there, and googling will turn up a multitude of results for more
information.

Date: Fri, 13 Jun 2003 18:01:32 +0200
From: Dallman Ross <dman(_at_)nomotek(_dot_)com>

I suggest that people use the Unix 'file' command to see if a
file contains a CRLF. Unfortunately not all versions of 'file'
support this. Does anyone have suggestions for easy ways for a
newbie to find out if a file contains a CRLF?

I would think "file" would be fine, but how about:

      grep -sq ^M$ spample && echo y

That's a real ^M in there.  I actually created it by typing
^C^J in my shell terminal.

-- 
dman

Hmm, I'm not familiar with the use of that key sequence, but that doesn't
mean it doesn't work. (It just means I'm not experienced enough. ;-)

    Chris


_______________________________________________
procmail mailing list
procmail(_at_)lists(_dot_)RWTH-Aachen(_dot_)DE
http://MailMan.RWTH-Aachen.DE/mailman/listinfo/procmail

<Prev in Thread] Current Thread [Next in Thread>