Converting LF to CR+LF 
Author Message
 Converting LF to CR+LF

Hi,

    I am working on a application which is written in C++ using Borland C++
Builder 4 for the Windows platform. The application issues a CGI-script on a
UNIX server (or clone thereof). The CGI-script runs a shell command (ls
/dir/subdir) which list the names from a certain directory. Since, the
application is Windows-based, it components work with CR (Carriage Return,
#13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

    I was told (in a Borland C++ Builder specific newsgroup) that I could
use a Perl script to convert the LF to CR+LF. Since, I have no experience
with Perl at all, I would like to know how I can put a CR in front of every
LF? Any help would be greatly appreciated.

Greetings,
Ramses Matabadal



Tue, 30 Dec 2003 01:15:22 GMT  
 Converting LF to CR+LF


Quote:
> Hi,

>     I am working on a application which is written in C++ using Borland
C++
> Builder 4 for the Windows platform. The application issues a CGI-script on
a
> UNIX server (or clone thereof). The CGI-script runs a shell command (ls
> /dir/subdir) which list the names from a certain directory. Since, the
> application is Windows-based, it components work with CR (Carriage Return,
> #13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

>     I was told (in a Borland C++ Builder specific newsgroup) that I could
> use a Perl script to convert the LF to CR+LF. Since, I have no experience
> with Perl at all, I would like to know how I can put a CR in front of
every
> LF? Any help would be greatly appreciated.

here's the complete perl script...

#!/bin/perl
while (<>) {
    s/\r\n/\n/;
    print;

Quote:
}

give it a filename on the command line and the new file will come from the
standard out. You can also just ftp the files in ascii mode.

jake



Tue, 30 Dec 2003 02:18:12 GMT  
 Converting LF to CR+LF
On Thu, 12 Jul 2001 19:15:22 +0200, "Ramses Matabadal"

Quote:

>Hi,

>    I am working on a application which is written in C++ using Borland C++
>Builder 4 for the Windows platform. The application issues a CGI-script on a
>UNIX server (or clone thereof). The CGI-script runs a shell command (ls
>/dir/subdir) which list the names from a certain directory. Since, the
>application is Windows-based, it components work with CR (Carriage Return,
>#13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

>    I was told (in a Borland C++ Builder specific newsgroup) that I could
>use a Perl script to convert the LF to CR+LF. Since, I have no experience
>with Perl at all, I would like to know how I can put a CR in front of every
>LF? Any help would be greatly appreciated.

>Greetings,
>Ramses Matabadal

Here's a perl one-liner:
perl -i -pe 's/\n/\r\n'


Tue, 30 Dec 2003 03:24:42 GMT  
 Converting LF to CR+LF
Thanks for the replies!

Greetings,
Ramses Matabadal



Quote:
> Hi,

>     I am working on a application which is written in C++ using Borland
C++
> Builder 4 for the Windows platform. The application issues a CGI-script on
a
> UNIX server (or clone thereof). The CGI-script runs a shell command (ls
> /dir/subdir) which list the names from a certain directory. Since, the
> application is Windows-based, it components work with CR (Carriage Return,
> #13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

>     I was told (in a Borland C++ Builder specific newsgroup) that I could
> use a Perl script to convert the LF to CR+LF. Since, I have no experience
> with Perl at all, I would like to know how I can put a CR in front of
every
> LF? Any help would be greatly appreciated.

> Greetings,
> Ramses Matabadal



Thu, 01 Jan 2004 18:22:13 GMT  
 Converting LF to CR+LF

Quote:



> > Hi,

> >     I am working on a application which is written in C++ using Borland
>  C++
> > Builder 4 for the Windows platform. The application issues a CGI-script on
>  a
> > UNIX server (or clone thereof). The CGI-script runs a shell command (ls
> > /dir/subdir) which list the names from a certain directory. Since, the
> > application is Windows-based, it components work with CR (Carriage Return,
> > #13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

> >     I was told (in a Borland C++ Builder specific newsgroup) that I could
> > use a Perl script to convert the LF to CR+LF. Since, I have no experience
> > with Perl at all, I would like to know how I can put a CR in front of
>  every
> > LF? Any help would be greatly appreciated.

> here's the complete perl script...

> #!/bin/perl
> while (<>) {
>     s/\r\n/\n/;
>     print;

You of course meant s/\n/\r\n/;

Ilya

- Show quoted text -

Quote:
> }

> give it a filename on the command line and the new file will come from the
> standard out. You can also just ftp the files in ascii mode.

> jake



Fri, 02 Jan 2004 07:57:31 GMT  
 Converting LF to CR+LF
are you sur it's \r\n and not \n\r ?????
Quote:




> > > Hi,

> > >     I am working on a application which is written in C++ using Borland
>  C++
> > > Builder 4 for the Windows platform. The application issues a CGI-script on
>  a
> > > UNIX server (or clone thereof). The CGI-script runs a shell command (ls
> > > /dir/subdir) which list the names from a certain directory. Since, the
> > > application is Windows-based, it components work with CR (Carriage Return,
> > > #13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

> > >     I was told (in a Borland C++ Builder specific newsgroup) that I could
> > > use a Perl script to convert the LF to CR+LF. Since, I have no experience
> > > with Perl at all, I would like to know how I can put a CR in front of
>  every
> > > LF? Any help would be greatly appreciated.

> > here's the complete perl script...

> > #!/bin/perl
> > while (<>) {
> >     s/\r\n/\n/;
> >     print;

> You of course meant s/\n/\r\n/;

> Ilya

> > }

> > give it a filename on the command line and the new file will come from the
> > standard out. You can also just ftp the files in ascii mode.

> > jake



Sat, 03 Jan 2004 17:41:44 GMT  
 Converting LF to CR+LF

Quote:

>     I am working on a application which is written in C++ using Borland C++
> Builder 4 for the Windows platform. The application issues a CGI-script on a
> UNIX server (or clone thereof). The CGI-script runs a shell command (ls
> /dir/subdir) which list the names from a certain directory. Since, the
> application is Windows-based, it components work with CR (Carriage Return,
> #13) *and* LF (Line Feed, #10). The UNIX server works only with LF.

>     I was told (in a Borland C++ Builder specific newsgroup) that I could
> use a Perl script to convert the LF to CR+LF. Since, I have no experience
> with Perl at all, I would like to know how I can put a CR in front of every
> LF? Any help would be greatly appreciated.

According to the documentation I've read \n is logical newline so in
that case if you don't mind a trailing newline should be:

$/="\cJ";
while( <STDIN> ) {
  chomp;
  print "$_\n";

Quote:
}

or if you mind:

$/="\cJ";
while( <STDIN> ) {
  if( chomp ) {
    print "$_\n";
  }
  else {
    print;
  }

Quote:
}

Haven't checked if it really works and can't check either since on my
system only linefeed is used for newline.


Tue, 06 Jan 2004 04:12:58 GMT  
 
 [ 7 post ] 

 Relevant Pages 

1. DOS Perl convering LF to CR/LF

2. Missing LF or getting an Extra LF ?

3. $/ = CR LF?

4. <FILE> and CR-LF

5. Binary data and CR-LF's in MSDOS

6. CR before login or any help that would lf before login

7. CR/LF

8. how to remove cr/lf ???

9. Question about formatting/(CR/LF) in PERL

10. Perl and CR+LF

11. Any Utility in Win32/Win95/Dos to remove CR or LF

12. CR LF to <br> in REGEX

 

 
Powered by phpBB® Forum Software