Grep to find files that contain ^M When ^m dos2unix and sed or "grep -r $'\r' *" does not work

1

I use Cygwin and made a txt file using a Perl script.

There is a ^M (Windows cariage return) added, and I have no idea how.

How do I find ^M when normal ways (^m dos2unix and sed or "grep -r $'\r' *") does not work?

when using less file01 I can see the ^M, but I am unable to match it with anything (not with \r nor with ^V^M).

When using Col (see man col) I get rid of it and several other things (I get a very, very strange output)

normal output:

JAN131005 GO:0009055 // GO:0020037 // GO:0003723 // GO:0006468 // GO:0016023 // GO:0003676 // GO:0003964 // GO:0005515 // GO:0004672 // GO:0000166 // GO:0004497 // GO:0006278 // GO:0009055 // GO:0020037 // GO:0003723 // GO:0006468 // GO:0016023 // GO:0003676 // GO:0003964 // GO:0005515 // GO:0004672 // GO:0000166 // GO:0004497 // GO:0006278 ^M // GO:0009055 // GO:0020037 // GO:0003723 // GO:0006468 // GO:0016023 // GO:0003676 // GO:0003964 // GO:0005515 // GO:0004672 // GO:0000166 // GO:0004497 // GO:0006278 ^M // GO:0003964 // GO:0003723 // GO:0006278 // GO:0005488 // GO:0003676 ^M // GO:0005622 // GO:0000166 // GO:0005886 // GO:0006950 // GO:0009628 // GO:0009719 // GO:0005515 // GO:0006950 // GO:0005515 // GO:0006950 // GO:0003674 // GO:0008150 // GO:0003676 ^M // GO:0003676 ^M // GO:0003964 // GO:0003723 // GO:0006278 // GO:0005488 // GO:0003676

after "col < file01 > test01" less test01 gives:

J//1GO:0003964 //OGO:0003723///OGO:0006278///OGO:0005488///OGO:0003676///OGO:0009719///OGO:0005515///OGO:0006950///OGO:0005515///OGO:0006950///OGO:0003674///OGO:0008150///OGO:0003676// GO:0009055 // GO:0020037 // GO:0003723 // GO:0006468 // GO:0016023 // GO:0003676 // GO:0003964 // GO:0005515 // GO:0004672 // GO:0000166 // GO:0004497 // GO:0006278

as you can see I have removed the problem, and replaced it with 2 others... Can anyone explain what col is removing here and how, as well as how I should remove it to just remove the ^M?

Stenemo

Posted 2013-07-18T10:13:50.257

Reputation: 266

The Windows carriage return is \r\n. Are you trying to remove it or convert it to a Linux \n? – Dane – 2013-07-18T16:20:18.167

Answers

2

The problem is that \r is not working, use \015 instead:

tr -d "\015" < inputfile > outputfile

for some reason \015 (an octal literal) works when \r, etc does not work.

Stenemo

Posted 2013-07-18T10:13:50.257

Reputation: 266

Nice, +1. Did you try sed 's/\r//g or perl -pe 's/\r//g'? They should also work. Actually, so should tr -d '\r'. – terdon – 2013-07-18T16:07:59.237

They both work! Thank you for that, I am quite certain I tried sed, but maybe I forgot. – Stenemo – 2013-07-20T11:33:12.487