Lets consider an example. I have a text file having the following text:
This is written in Microsoft Word for Mac, and saved as a text file.
When imported to UNIX, the contents of the file appear as one long paragraph. (see pic below)
This is because in Mac OS formatting, every new line is marked with ASCII character 15 (carriage return) while in UNIX every new line is marked with a line-feed (ASCII character 12).
So a small script that replaces every occurrence of ‘\15’ with ‘\12’ will do the trick and make the file readable to UNIX.
The tr command replaces every occurrence of a character with another.
tr ’15’ ’12’ <source_file> destination_file
We can make a usable script by typing the following in a text file:
tr ’15’ ’12’ <“$x”> “$x.temp”
mv “$x.temp” “$x”
We can execute this script with multiple files as command line inputs.
I have named my script as “converter.sh”
sh converter.sh file1 file2 …