There is a difference in how Windows and Unix-based systems end their lines. Why does this matter to us?
When converting the configs for the INE workbook vol1 the configs have been made by someone using Windows.

Windows uses a carriage return and a linefeed for each new line. The carriage return can be expressed as r or ^M.
After that we have a linefeed which is expressed n or ^J. When using a Unixbased system only the n is used.

How can I convert from DOS-format to Unix, well there are a lot of different ways of doing this.
We can do it by using sed but there is a easier way. There is a utility called dos2unix, I run Debian on my Dynamips
box and I couldn’t find a package called dos2unix but there is a package named tofrodos that contains dos2unix.
To install it use:

sudo apt-get install tofrodos

Then answer yes to install it. Using it is easy, this is the syntax:

dos2unix r1.txt

This will clean up the file and output it with the same name it already has (overwriting). If you want to put the result in a new file then use:

dos2unix r1.txt r1-new.txt

If you have had issues with running my script this might be why. If you open a DOS-formatted text-file with Nano it will say that it has been
converted from DOS-format. I probably could have solved this in the script but my Unix skills are very limited and as I pick things up I will
try to improve it. Please leave comments if you use the script and if you have made any improvements to it. I want the community and all
us future CCIEs to have the tools needed readily available for sucessful studies.

Tagged on:         

One thought on “Dos2unix

  • January 30, 2011 at 3:35 pm

    Just had this exact problem:

    [[Router R1]]^M
    model = 3725^M
    console = 2001^M
    autostart = false^M
    #slot1 = NM-4T^M
    # F0/0 = SW1 F1/1^M
    S0/0 = FRSW 1^M

    On Ubuntu 10.10, dos2unix is it’s own package


Leave a Reply

Your email address will not be published. Required fields are marked *