Solved

Unix to Windows CRLF

Posted on 2003-10-24
12
1,562 Views
Last Modified: 2013-12-26
Hi ya,

I FTP a file from a Unix box to a Windows FTP Sever in binary mode.  The line feed character from Unix does not get converted to CRLF in Windows since I am in binary mode.  Is there a way in Unix to change the LF  to Windows compatable CRLF? I would prefer to use a built in Unix command instead of a third party utility.  

Thanks!
0
Comment
Question by:jmnason
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
  • 2
  • +4
12 Comments
 
LVL 1

Expert Comment

by:Satalink
ID: 9614302
vi filename
:set list show

replace all $ with ^M

:/g/$/s//^M/g

thing that should work
0
 

Author Comment

by:jmnason
ID: 9614343
Thanks Satalink, but I want some command that I can automate my process. I create a XML file in Unix, encrypt it and send the file to the windows FTP server and this is automated.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9614434
There are several tools to accomplish that, the most common (and likely to be installed) are

unix2dos <filename>

or

recode lat1..ibmpc <filename>
0
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 86

Assisted Solution

by:jkr
jkr earned 125 total points
ID: 9614524
BTW, the 1st one usually is implemented as a 'shell alias' like

   alias unix2dos='recode lat1..ibmpc'
   alias dos2unix='recode ibmpc..lat1'
0
 
LVL 16

Accepted Solution

by:
_nn_ earned 125 total points
ID: 9615307
Just to mention them, sed oneliners found on http://sed.sourceforge.net/sed1line.txt

 # IN UNIX ENVIRONMENT: convert Unix newlines (LF) to DOS format
 sed "s/$/`echo -e \\\r`/"            # command line under ksh
 sed 's/$'"/`echo \\\r`/"             # command line under bash
 sed "s/$/`echo \\\r`/"               # command line under zsh
 sed 's/$/\r/'                        # gsed 3.02.80

0
 
LVL 9

Expert Comment

by:HamdyHassan
ID: 9619332
Is your file will be bad if ftp in ascii mode?
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9620818
'cause you did not tell us your UNIX flaviour, and unfortunately each has its own program/script/alias/whatever to do it, I'd sugest a general perl solution:
perl -pe 'BEGIN{ $/="\012"; $\="\015\012"} chomp' unixfile >dosfile
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9631253
Why not just FTP the file in ASCII mode?  Much simpler.
0
 
LVL 86

Expert Comment

by:jkr
ID: 9633642
>>Why not just FTP the file in ASCII mode?

Because the files will still get displayed incorrectly in Windows applications...
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9634202
>>Why not just FTP the file in ASCII mode?

'cause you never know how  "ASCII"-mode is defined in your ftp client *and* ftpd-server, be prepared for surprises ...
0
 
LVL 48

Expert Comment

by:Tintin
ID: 9637191
ahoffmann,

Agree with your comments about ftp client/server, *but* if you have a known environment, you know what client/server you operate and will know whether ASCII transfers work as they should.
0
 
LVL 51

Expert Comment

by:ahoffmann
ID: 9641105
agreed, but if you know all this, then there's no need for this question :-))
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Ownerdraw of the grid button.  A singleton class implentation and usage. Continuing from the fifth article about sudoku.   Open the project in visual studio. Go to the class view – CGridButton should be visible as a class.  R…
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question