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

what's a one-liner to strip leading white space from a file and put the results into another file? perl -e 's/^\s+//g while <>' file > file2 # best I could get so far :(

Replies are listed 'Best First'.
Re: strip white space one-liner
by maverick (Curate) on Nov 12, 2001 at 01:29 UTC
    perl -p -e 's/^\s+//' < file1 > file2
    the -p wraps a while loop reading from standard in with a print $_ at the bottom of whatever you put in -e.

    in other words

    while(<>) { # whatever is in -e print $_; }

    /\/\averick
    perl -l -e "eval pack('h*','072796e6470272f2c5f2c5166756279636b672');"

Re: strip white space one-liner
by Fletch (Bishop) on Nov 12, 2001 at 08:56 UTC

    If you want things to be munged in place use -i

    perl -i.bak -pe 's/^\s+//' foo

    If you don't want a backup copy, omit the backup suffix. See perldoc perlrun for more information.