Solved

Unix to Windows CRLF

Posted on 2003-10-24
12
1,502 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
  • 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
 
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
Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Here is how to use MFC's automatic Radio Button handling in your dialog boxes and forms.  Beginner programmers usually start with a OnClick handler for each radio button and that's just not the right way to go.  MFC has a very cool system for handli…
Introduction: The undo support, implementing a stack. Continuing from the eigth article about sudoku.   We need a mechanism to keep track of the digits entered so as to implement an undo mechanism.  This should be a ‘Last In First Out’ collec…
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.
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

757 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now