Solved

Unix to Windows CRLF

Posted on 2003-10-24
12
1,517 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Introduction: Displaying information on the statusbar.   Continuing from the third article about sudoku.   Open the project in visual studio. Status bar – let’s display the timestamp there.  We need to get the timestamp from the document s…
Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
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.

813 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

16 Experts available now in Live!

Get 1:1 Help Now