Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
    
The Windows carriage return is \r\n. Are you trying to remove it or convert it to a Linux \n? –  Dane Jul 18 '13 at 16:20

1 Answer 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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 Jul 18 '13 at 16:07
    
They both work! Thank you for that, I am quite certain I tried sed, but maybe I forgot. –  Stenemo Jul 20 '13 at 11:33

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.