Search code examples
perlflat-filestrawberry-perl

Why won't Strawberry Perl remove these form feed characters?


I'm currently running Strawberry Perl on WinXP, and I'm trying to process a unix-formatted flat file. The flat file uses line feed characters to delimit fields, and form feed characters to delimit a record. I am trying to convert the FF to anything else (CRLF, ';', TAB, etc). I have tried using the following perl one-liners with no success:

perl -p -e 's/\f/\r\n/g' < unix.txt > dos.txt
perl -p -e 's/\x0c/\x0d\x0a/g' < unix.txt > dos.txt
perl -p -e 's/\f/\t/g' < unix.txt > dos.txt

The only thing I've noticed is that the the dos.txt ends up with all the LF chars converted to CRLF, but the FF chars remain. I've even tried to reprocess the dos.txt file, again trying to replace the FF, but still no dice. I am still very much a perl newbie, so maybe I'm missing something? Does anyone know why the above commands don't do what I want them to do?


Solution

  • The problem is that the Windows shell doesn't interpret single quotes the way the Unix shell does. You should use double quotes in your commands.

    C:\ perl -e "print qq/foo\fbar/" > test.txt
    C:\ type test.txt
    foo♀bar
    C:\ perl -pe 's/\f/__FF__/' < test.txt
    foo♀bar
    C:\ perl -pe "s/\f/__FF__/" < test.txt
    foo__FF__bar