Visit Jeremy's Blog.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 07-06-2003, 02:01 AM   #1
LQ Newbie
Registered: Jul 2003
Location: Michigan
Posts: 21

Rep: Reputation: 15
DOS -> UNIX file conversion issue

Hey guys...
I have good news and bad news... (for me anyway )
Good new:
After many bashes of the head against the nearest brick wall I finally figured out why my CGI scripts sometimes don't work on some machines...

It turns out that the reason is if I edit the perl script on a windows box and upload it, it now is DOS formatted... this seems to be a bad thing for apache anyway on linux machines...
So to fix it I have found that I can copy the text out of the newly edited DOS formatted file and paste it into a file that I made on a linux machine... then save the new file over the old one...
Cool.. this seems to work... however I was looking for a less crude way of doing it... after a little searching I found that there
is a command dos2unix... I thought this would be the answer.. however it didn't quite work for me... Soooooo... I need a better solution...

the PERL scripts that work show up in EMACS with the litte "u" on the left side of the message bar at the bottom of the window... After I use dos2Unix on a file I don't get a "u" or a "(DOS)"... and I still get the same error from apache "Premature end of script headers".... the above solution does fix this but its a crappy fix...

this overly long winded question can be brought down to a few...
"Any ideas?"

oh.. and after each conversion I did check to make sure that the file permissions were set properly... so that isn't the problem

thanks so much for your help!!

Old 07-06-2003, 11:30 AM   #2
Registered: Mar 2003
Location: Scotland
Distribution: Slackware, RedHat, Debian
Posts: 12,047

Rep: Reputation: 67
Take a look at NoteTab lite:

It can save files in UNIX format.
Old 07-06-2003, 03:52 PM   #3
LQ Newbie
Registered: Jul 2003
Location: Michigan
Posts: 21

Original Poster
Rep: Reputation: 15
thanks for the suggestion! I will definatly look into it, however
I was looking for a way to do it in linux... thanks!

Old 07-08-2003, 02:15 PM   #4
LQ Newbie
Registered: Jun 2003
Distribution: Mandrake 9.1
Posts: 17

Rep: Reputation: 0
Look - I have no idea of specifics , but your problem revolves around <CR> <LF> and dos to nix conversion as per my own experience - I could very well be wrong. Anyway - what I used to do was a small script - put in ascii and bring back in binary (perhaps the other way around - forgot now ) at the windows command prompt for 2 or 3 times. It works fine and can be automated when your lan has any nix box . Also most ftp s/w have options for crlf conversion , yu can explore that.
Hope this helps you .
Old 07-08-2003, 09:59 PM   #5
Registered: Jun 2003
Location: Denver, CO
Distribution: Debian
Posts: 95

Rep: Reputation: 15
To convert DOS text to Unix text, at the console:

perl -i.bak -pe "s[\x0d\x0a][\x0a]g" <filename>

Note that <filename> can include wild cards. Your original file will be backed up with a .bak extension.

Also note that it's ZERO D and ZERO A, not OH D and OH A.
Old 07-04-2004, 12:24 AM   #6
Registered: Jun 2004
Location: QC, Philippines
Distribution: Ubuntu
Posts: 30

Rep: Reputation: 15
here's what I use
(dos to unix)

sed -e s/'\r'// yourDosFile > newFile


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SED - Converting UNIX to DOS file aurelio26 Linux - Newbie 7 04-09-2008 12:15 AM
Dos to unix newlines Rotwang Linux - General 3 08-22-2005 01:45 PM
newline problem between DOS and Unix format cjs_pro Programming 7 03-11-2005 11:08 AM
Perl file conversion results in a truncated file kshaffer Programming 0 01-31-2005 02:31 PM
Unix to DOS text Wynd Programming 5 04-18-2003 12:14 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 09:46 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration