LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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: 96
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: 96
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: 96
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: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
tr -d '\015'
works ok.
 
Old 03-11-2005, 07:05 AM   #7
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: FreeBSD, Debian, Mint, Puppy
Posts: 3,283

Rep: Reputation: 172Reputation: 172
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: LFS-Version SVN-20091202, Arch 2009.08
Posts: 1,484

Rep: Reputation: 66
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


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
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


All times are GMT -5. The time now is 10:17 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration