LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-15-2003, 08:36 PM   #1
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Rep: Reputation: 32
Unix to DOS text


I have this shell script that converts a DOS text file to Unix format (different end-of-lines). How would I write it to do the reverse?

Code:
if [ -z "$1" ]
then
  echo "Usage: `basename $0` filename-to-convert"
  exit 1
fi

# Lines in a DOS text file end in a CR-LF.
CR='\015'  # Carriage return.

# Delete CR and write to new file.
tr -d $CR < $1
 
Old 04-15-2003, 09:53 PM   #2
moses
Senior Member
 
Registered: Sep 2002
Location: Arizona, US, Earth
Distribution: Slackware, (Non-Linux: Solaris 7,8,9; OSX; BeOS)
Posts: 1,152

Rep: Reputation: 50
"DOS format" has two end of line characters, carriage return and line feed. "ISO format" has just the line feed. You would need to add a carraige return to each line. Of course, you knew that. What you may not know is that this has been done. A quick google search on dos2unix or unix2dos will give you all sorts of ways to convert files, from Perl scripts, to sed one-liners to C programs.
 
Old 04-16-2003, 02:56 PM   #3
cdw
LQ Newbie
 
Registered: Dec 2002
Distribution: slackware8.1
Posts: 5

Rep: Reputation: 0
Open *nix text files with Wordpad.
 
Old 04-16-2003, 03:05 PM   #4
Tinkster
Moderator
 
Registered: Apr 2002
Location: earth
Distribution: slackware by choice, others too :} ... android.
Posts: 23,067
Blog Entries: 11

Rep: Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928Reputation: 928
Slack comes with
fromdos
and
todos ;)

Cheers,
Tink
 
Old 04-17-2003, 10:38 AM   #5
pilgrim22
LQ Newbie
 
Registered: Mar 2003
Location: TX
Distribution: SuSE/RedHat
Posts: 5

Rep: Reputation: 0
RedHat 7.2 (older distros in general?) had the utils "dos2unix" and "unix2dos". Don't know for sure if current ones do - check your distro packages. They are pretty self-explanatory, but have man pages for the overly curious!
 
Old 04-18-2003, 12:14 PM   #6
Wynd
Member
 
Registered: Jul 2001
Distribution: Slackware 12
Posts: 511

Original Poster
Rep: Reputation: 32
Quote:
Originally posted by Tinkster
Slack comes with
fromdos
and
todos

Cheers,
Tink
Thanks - that's exactly what I was looking for
 
  


Reply



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
Convert DOS text files to UNIX text files ta0kira Linux - Software 7 03-15-2011 11:42 AM
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
DOS -> UNIX file conversion issue inspleak Linux - Newbie 5 07-04-2004 12:24 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:03 PM.

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