Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1597
  • Last Modified:

Unix to Windows CRLF

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
jmnason
Asked:
jmnason
  • 3
  • 3
  • 2
  • +4
2 Solutions
 
SatalinkCommented:
vi filename
:set list show

replace all $ with ^M

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

thing that should work
0
 
jmnasonAuthor Commented:
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
 
jkrCommented:
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!

 
jkrCommented:
BTW, the 1st one usually is implemented as a 'shell alias' like

   alias unix2dos='recode lat1..ibmpc'
   alias dos2unix='recode ibmpc..lat1'
0
 
_nn_Commented:
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
 
HamdyHassanCommented:
Is your file will be bad if ftp in ascii mode?
0
 
ahoffmannCommented:
'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
 
TintinCommented:
Why not just FTP the file in ASCII mode?  Much simpler.
0
 
jkrCommented:
>>Why not just FTP the file in ASCII mode?

Because the files will still get displayed incorrectly in Windows applications...
0
 
ahoffmannCommented:
>>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
 
TintinCommented:
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
 
ahoffmannCommented:
agreed, but if you know all this, then there's no need for this question :-))
0

Featured Post

Independent Software Vendors: 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!

  • 3
  • 3
  • 2
  • +4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now