The problem
On Gentry, enter:
wget http://it.metr.ou.edu/dos2unix/fromwindows.zip
Gentry has
the utility to unzip it:
unzip fromwindows.zip
and out pops fromwindows.py. Then,
cat fromwindows.py
reveals:
#!/usr/bin/env python
#this was made using Notepad in Windows
print "Good morning starshine, I'm from Windows!"
You can probably figure out what the program is intended to do.
You probably think you know
what you need to do to make the program executable. But you might find that
the s.o.b. thing just doesn't work. On Gentry you will
get an error:
: No such file or directory
Huh? Which file or directory is there "no such"? Weird.
The problem is that in
DOS/windows files, lines are ended with both a carriage return
and a linefeed (python's "\r" and "\n", ascii \015 and \012) while unix uses
just a linefeed character.
If you do
cat -ve fromwindows.py
you will see all the "\r" rendered with a ^M, and all the "\n" with a $:
#!/usr/bin/env python^M$
#this was made using Notepad in Windows^M$
print "Good morning starshine, I'm from Windows!"^M$
The solution
dos2unix fromwindows.py
cat -ve fromwindows.py
The pesky ^M should be gone and the "killer app" fromwindows.py will be ready to go.
For quick inspection of bigger files, use:
cat -ve fromwindows.py | head
That will pipe the output of cat into head and
show only the first 10 lines.
If you edit fromwindows.py with gvim or vim (which most
of you probably do not)
you will find a message [dos] at the bottom of the gvim window.
This is also seen in the set summary resulting from entering the vim command set.
You will see: fileformat=dos.
To easily convert the file in your editor: set ff=unix.
Know this vim command also: set list.
See
Dealing with Makefile and other SOB files.
This is also interesting for vim users, at least to to see the pain and suffering:
Tip #26: Getting rid of ^M - mixing dos and unix
Link(s)