LinuxQuestions.org
Help answer threads with 0 replies.
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 03-10-2005, 08:23 PM   #1
cjs_pro
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Rep: Reputation: 0
newline problem between DOS and Unix format


Hi all,

I have a bash script file which use SED to replace the version number of a VisualC++ resource file. The SED command looks like:
sed -e 's/FILEVERSION *[0-9]* *, *[0-9]* *, *[0-9]* *, *[0-9]*[ ]*/FILEVERSION $2,$3,$4,$5/g'
After the replacement, I opened the resource file with notepad on my XP computer. I found that all lines are wrapped into a line. However, I opened the same resource file with notepad on my another XP computer, and each line is displayed properly.
Q1. What setting differences on XPs would cause such notepad display difference?

I then added another SED command in the base script
sed -e 's/$/\r/' < "$file1" >| "$file2"
to insert a \r to each line of the replaced resource file.
When I opened the resource file2, I found all lines ending up with a "r" character.
Q2. What is the way to solve the newline problem between dos and unix format properly?

Thank you
 
Old 03-10-2005, 09:27 PM   #2
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Hi.

Q1: No idea.

Q2: There's a pair of utilities to do this: unix2dos and dos2unix. They're probably already installed on your Linux box.

Dave
 
Old 03-10-2005, 09:56 PM   #3
cjs_pro
LQ Newbie
 
Registered: Jul 2004
Posts: 8

Original Poster
Rep: Reputation: 0
Hi Dave,

Thank you for your reply. I tried to avoid relying on the third party utilities which are not standard tools within my working environment. Certainly ,there should be a simple way to do that by SED or AWK.

Thank you
 
Old 03-10-2005, 10:25 PM   #4
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
unix2dos and dos2unix are standard utilities as far as Linux goes. I'm not too sure about other unices.

If you insist on re-inventing the wheel, though, have a look here:
http://www-106.ibm.com/developerwork...ry/l-sed3.html

Dave
 
Old 03-10-2005, 10:29 PM   #5
ilikejam
Senior Member
 
Registered: Aug 2003
Location: Glasgow
Distribution: Fedora / Solaris
Posts: 3,109

Rep: Reputation: 97
Just noticed this from the linked page:
Quote:
Please note that the '\r' will be replaced with a CR only when using GNU sed 3.02.80 or later.
Dave
 
Old 03-11-2005, 07:01 AM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
tr -d '\015'
works ok.
 
Old 03-11-2005, 07:05 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
Quote:
Q1. What setting differences on XPs would cause such notepad display difference?
Windows is after all these years developing some intelligence?

On my old 98 machine at work notepad does as you say but wordpad
reads correctly.

Obviously they have finally updated notepad!!
 
Old 03-11-2005, 11:08 AM   #8
exvor
Senior Member
 
Registered: Jul 2004
Location: Phoenix, Arizona
Distribution: Gentoo, LFS, Debian,Ubuntu
Posts: 1,537

Rep: Reputation: 87
No thats not it at all


the proper answer to Q1 is

In notepad you have the option to enable word wrap or not.


On one computer this is enabled so notepad reconized the new line char in the text document
on the other computer this is not the case. EX the option is turned off.



Open the document in wordpad to avoid this issue.
 
  


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
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
Why do file names keep getting changed to dos 8.3 format on my usb drive? firehawk256 Linux - Newbie 1 02-25-2005 03:32 PM
DOS -> UNIX file conversion issue inspleak Linux - Newbie 5 07-04-2004 12:24 AM
Unix to DOS text Wynd Programming 5 04-18-2003 12:14 PM

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

All times are GMT -5. The time now is 03:42 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