[ale] some other regexp

Cor van Dijk cor.angela at mindspring.com
Mon Jun 28 10:52:29 EDT 1999


Ryan Bridges wrote:

> I need to strip the Linefeeds out of a file.  I discovered that this is
> not a newline (\n) but something else.  I have tried everything I can
> think of and connot get rid of them. Anyone have any ideas?  PERL didn't
> work so far and I am not good with sed/awk...
> Thanks again in advance,
> Ryan
>
> ----------------------------------------------------------------
> Ryan Bridges <ryan at linuxgeneralstore.com>
> B.Gates : quality software :: R.McDonald : gourmet cuisine
> ----------------------------------------------------------------

I tested succesfully the following script on a Linux system
--------------------------------------------
#!/usr/bin/perl
# This script will do a pattern substitution in a file
# Usage "subst1 <filename>"
# For a new substitution edit "old" and "new" in
# $file[$linenum] =~ s/old/new/gi;

open (FILE, "$ARGV[0]");
        @file = <FILE>;
        $linenum = 0;
        while ($file[$linenum] ne "" ) {
                        $file[$linenum] =~ s#\cJ#linefeed#g;
                $linenum++;
        }
close (FILE);
open (FILE, ">$ARGV[0]");
        print FILE (@file);
close (FILE);
print ("Lines processed: $linenum \n");
-----------------------------------------------------
See Perl Cookbook page 292. The secret is in "\cJ" (Ctrl-J).






More information about the Ale mailing list