Mac OS X produces files with just an LF the end of each line. Windows produces files with both CR and LF.
I ran into a problem building HEX files with MPLAB X IDE on my Mac, the hex files had just LF’s terminating each line but my downloading process required that I have CR and LF marking EoL.
The internet–and I don’t reference one site because I found this in many places–had the answer as usual.
Here is a short Perl incantation that can replace each LF with a CRLF:
perl -pi -e 's/\r\n|\n|\r/\r\n/g' YOURFILENAMEHERE
I use the above as part of a bash script that automatically converts and uploads my hex files to a server:
#!/bin/bash
fwVer=$(date +%y%m%d%H%M%S)
if [ -n "$1" ]
then
fwVer=$1
fi
perl -pi -e 's/\r\n|\n|\r/\r\n/g' /my/local/path/myprojectfile.hex
scp /my/path/myfile.hex myuser@my.server.com:/my/remote/path/$fwVer.hex
If I supply an argument when calling the script it will use that name when uploading the file, otherwise it will name the file based on the current time using YYMMDDHHMMSS format which allows the latest files to sort up to the top of a list and gives you some clues about when you built one vs. the other.
A quick note, there is no line break in the scp command, but it may appear that way due to formatting on this page.