auzten has asked for the wisdom of the Perl Monks concerning the following question:

After converting some DOS text with:
perl -pi -e 's/\r//g' filename.txt
I have these random ^L in the file that blows another
script up. Any idea how to replace these with \n?
-auzten

Replies are listed 'Best First'.
Re: Replacing ^L with \n
by suaveant (Parson) on Apr 05, 2001 at 22:28 UTC
    \cL will match ^L
                    - Ant
      Or \f works too. Perl has a basically completely unused shortcut for formfeed thanks to its early use in puking reports to cruddy lineprinters. =)

      --
      $you = new YOU;
      honk() if $you->love(perl)

Re: Replacing ^L with \n
by deprecated (Priest) on Apr 05, 2001 at 22:34 UTC
    warning, non perl solution below!

    Because youre using the expression "some DOS text" I will (possibly mistakenly) assume that you are using a *nix. In which case, you can use perl but its sort of overkill. I would use sed(1).

    [alex@creamy]$ sed 's:^L:\n:g' filename > filename.out
    of course, to create a ^L you actually need to do a ^V^L or your shell will assume you really mean ^L. Also, \n is native to the gnu sed, and may not work in BSD or ATT *nix's.

    brother dep.

    --
    Laziness, Impatience, Hubris, and Generosity.

      That ended up replacing ^L with the actual character n, not a carriage return.

      I tried this and it worked:

      perl -pi -e 's/^L/\n/g' file.txt

      Maybe I should learn something about regular expressions?

      Muchos Gracias
      -auzten
Re: Replacing ^L with \n
by yakko (Friar) on Apr 05, 2001 at 23:51 UTC
    tr/\f/\n/;
    ... is another way to convert it.

    --
    Me spell chucker work grate. Need grandma chicken.

Re: Replacing ^L with \n
by swiftone (Curate) on Apr 05, 2001 at 22:43 UTC
    Ant has demonstrated how you can replace it. I just wanted to drop an FYI and mention that ^L was the traditional page feed (i.e. page break for printing) on DOS boxes (I suspect it has earlier origins, but I don't know them).

    Just in case you were curious what they were.