perlfileuppercase

How can I write a Perl script to convert file to all upper case?


How can I write a Perl script to convert a text file to all upper case letters?


Solution

  • Use:

    perl -ne "print uc" < input.txt
    

    The -n wraps your command line script (which is supplied by -e) in a while loop. A uc returns the ALL-UPPERCASE version of the default variable $_, and what print does, well, you know it yourself. ;-)

    The -p is just like -n, but it does a print in addition. Again, acting on the default variable $_.

    To store that in a script file:

    #!perl -n
    print uc;
    

    Call it like this:

    perl uc.pl < in.txt > out.txt