[clug] Circumflex

Scott Ferguson scott.ferguson.clug at gmail.com
Mon Aug 21 01:38:25 UTC 2017

On 21/08/17 04:21, Bryan Kilgallin (iiNet) via linux wrote:
> Thanks again Scott:
> The problem was with the sample text file. I think that some unfortunate
> CR/LF line-ending combination had caused trouble.

You can test for dos text files in a directory with:-
grep -lU $'\x0D' *

(which matches on the hex for CRLF)

or grep a file for a line that end with a carriage return:-
[[ $(grep -c $'\r$' crlf.txt) -gt 0 ]] && echo dos

or use dos2unix to check a directory of text files:-

dos2unix -ic *.txt

Of course "file" will also tell you whether it's a MS-DOS-style text file:-
file crlf.txt
crlf.txt: ASCII text, with CRLF line terminators

You can pipe through "dos2unix" (which converts MS-DOS-style text files
to UNIX-style text files)

cat crlf.txt |grep }$

cat crlf.txt|dos2unix |grep }$
        guidExtensionCode         {7033f028-1163-2e4a-ba2c-6890eb334016}
        guidExtensionCode         {82066163-7050-ab49-b8cc-b3855e8d221e}
        guidExtensionCode         {82066163-7050-ab49-b8cc-b3855e8d221f}
        guidExtensionCode         {82066163-7050-ab49-b8cc-b3855e8d2252}

or use "sed" to change the line endings:-

sed 's/\r$//'

and then there's awk and perl (which will do the same thing)...

> Whereas with a different sample text file, the grep operations worked fine!

grepping MS-DOS-style text files is a bit tricky (depending on your
version of grep).
Normally grep guesses if the file is text - and ignores the carriage
returns if it guesses the file is text. You can override this with -U
which forces grep to treat the file as binary and read the carriage returns.

Kind regards

    A: Because we read from top to bottom, left to right.
    Q: Why should I start my reply below the quoted text?

    A: Because it messes up the order in which people normally read text.
    Q: Why is top-posting such a bad thing?

    A: The lost context.
    Q: What makes top-posted replies harder to read than bottom-posted?

    A: Yes.
    Q: Should I trim down the quoted part of an email to which I'm reply


More information about the linux mailing list