Cleanup Unprintable Characters.

Someone transferred files in binary rather then ascii, and this resulting in the ^M character appearing at the end of the lines in the script. Because of this, they would not execute, here’s how to clean them up.
If it’s one script, then you can open the file in vi, remove the end of each line and save the file. But what if you have a hundred files, how would you clean them all out ?
Using the strings command, which removes unprintable characters, you can cat each file through the strings command and write it back to the original name. Again, with many files this will still take a long time.
strings >
So, with this in mind, just create a script to do it (I use ksh for the for loop command).
for file in *.sh
strings ${file} > fred
mv fred ${file}
This will go through each file, use stings to clear it out and create file fred, then move fred back to the original file. Note that this removes all permissions from the file, and you may require to reset this afterwards.
This entry was posted in AIX and tagged , , , , . Bookmark the permalink.