Strange Linefeed Characters Appearing on Mac
Had a funny situation today where I was emailed a bash program file, but simply downloading the attachment from gmail (in Chrome) added a linefeed (\r) to the file.
This is strange because I never actually opened the file to edit, so I’m not sure what was writing those chars to the file. I’m on a Mac (OSX 10.6.8), so I get the line feed character in general, but just not in this case as the file was never opened.
The following command shows (among other things) the non-printing characters:
od -c filename | sed 4q
You can see the offending \r which was breaking the bash program. The unix tool dos2unix was suggested to clean up the file. Unfortunately this wasn’t available on Mac by default. MacPorts to the rescue (I assume homebrew would be a good option as well):
1 2 3 4 5 6 7 8 9 10 11 12
Then run the program to clean up the invalid line feed (on 2 files).
1 2 3 4
Nice! The changes are: