changing all characters of a file to capital letters

Hi guys.

I have file named output.txt containing file names. one per line. I use this command to convert all characters to capital letters and write to the same file.

cat output.txt | tr 'a-z' 'A-Z' > output.txt

But at the end output.txt is emtpy. Could anyone help??

tr a-z A-Z < output.txt > _out &&
  mv -- _out output.txt
1 Like

I Know the solution. I want to know why this occurs? :smiley:

Move o/p to temp file and mv it ..

$ tr -s '[:lower:]' '[:upper:]' < infile > dummy_file ; mv dummy_file infile

It happens because the redirection is performed before the rest of the operations :slight_smile:

1 Like
perl -lane 'print uc($_)' inputfile > outputfile

Or:

perl -i -pe'$_ = uc' inputfile