Solved

Unix to Windows CRLF

Posted on 2003-10-24
12
1,530 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
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.

 
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

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
How to create frequencies of a variable from SAS dataset? 10 133
Host to IP 7 80
ORA-01403: no data found 43 105
substring method in java 1 129
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: Load and Save to file, Document-View interaction inside the SDI. Continuing from the second article about sudoku.   Open the project in visual studio. From the class view select CSudokuDoc and double click to open the header …
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.
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

790 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