0

I have a text file as "temp" with contents

Hai! How are you

I wanted to change the contents of the same file to

HAI! HOW ARE YOU

When i used cat temp |tr a-z A-Z (---only output was shown as upper case. The file remain unchanged....). I wanted the file contents to be changed. On Using cat temp |tr a-z A-Z>>temp (--the out was appended not overwritten). Kindly help

jww
  • 97,681
  • 90
  • 411
  • 885
anitha
  • 1
  • 1
  • Welcome to SO, please try to wrap your samples in CODE TAGS a `{}` button in your post, also try to show your efforts too(in code tags only). – RavinderSingh13 Jul 09 '18 at 11:00

3 Answers3

0

You can use a temporary file to store the result:

cat temp | tr "a-z" "A-Z" > t
rm temp
mv t temp

Using sed should also work:

sed -i 's/./\U&/g' temp
Poshi
  • 5,332
  • 3
  • 15
  • 32
0

Read content from temp, convert it to upper case and write it back to temp:

echo "$(awk '{print toupper($0)}' < temp)" > temp
Rene Knop
  • 1,788
  • 3
  • 15
  • 27
0
cat temp |tr a-z A-Z>>temp 

will not overwrite becouse of double '>'


To overwrite content use single '>'

cat temp |tr a-z A-Z>temp 
Alex
  • 409
  • 6
  • 15