in reply to Removing Control Characters from a File

This will remove ^X's from your file
perl -0777lpwi -030e0 your_file

Study of man perlrun will explain why this works.

Abigail

Replies are listed 'Best First'.
Re: Re: Removing Control Characters from a File
by jmcnamara (Monsignor) on Jun 04, 2002 at 22:57 UTC

    Very nice. This merits a closer look:
    perl -0777lpwi -030e0 file 0777 Set $/ to 0777. l Chomp $\ and set $\ = $/. Thus $\ = 0777. p Loop over file and print. w Turn warnings on. i Make the changes in-place. 030 Set $/ to 030 (^X). $\ is still 0777. e0 Empty program.

    So in effect this splits the file into records divided by ^X, chomps ^X from the end of each record and prints out the records with 0777 appended at the end. However, (and I'm not certain about this) since there is no character with that value it actually appends ''. Thus, the ^X's are removed from the file.

    So in a way the program is functionally equivalent to:     perl -i -pe 's/\30//g' file

    I say functionally equivalent since there is no aesthetic equivalence. :-)

    --
    John.