Saturday, March 21, 2009

10) Script converting ACII files from DOS to UNIX format

Shell scripts written in a notepad, notepad2, notepad++ etc encounter errors when executed in shell. For users who use unix environments on their Windows system, this would be a problem as scripting is often done using text editors from windows. This occurs in scripts with multiple lines of code. In DOS formatting, a new line includes two characters, a line feed and a carriage return. Unix formats use only the line feed character for a new line. In order to make your file executable, run the following command in shell:

>tr -d '\15' < infile > OUTFILE

The above code removes all carriage returns (ASCII code \15) from each line. Make sure that your outfile and infile have different names, and remember to inlude your extensions. Your outfile can  now be executed in unix shell once you have made it executable.

1 comment: