LoginSignup
3

More than 5 years have passed since last update.

trコマンドでの大文字化(小文字化)

Posted at

trコマンドはcharacterを置換することができる。これを使ってアルファベットを大文字かする場合は以下のようにすればいける。


$ cat nobita.txt
My name is Nobita. I'm 10 years old. Nice to meet you.
$ cat nobita.txt | tr [a-z] [A-Z] 
MY NAME IS NOBITA. I'M 10 YEARS OLD. NICE TO MEET YOU.

trにはこの他にもclassと呼ばれるものがあり、これを使って大文字化(小文字化)することもできる。

$ cat nobita.txt | tr [:lower:] [:upper:]
MY NAME IS NOBITA. I'M 10 YEARS OLD. NICE TO MEET YOU.

このclassには他にも以下のようなものがあるらしい。

$ man tr

~

     [:class:]  Represents all characters belonging to the defined character class.  Class
                names are:

                alnum        <alphanumeric characters>
                alpha        <alphabetic characters>
                blank        <whitespace characters>
                cntrl        <control characters>
                digit        <numeric characters>
                graph        <graphic characters>
                ideogram     <ideographic characters>
                lower        <lower-case alphabetic characters>
                phonogram    <phonographic characters>
                print        <printable characters>
                punct        <punctuation characters>
                rune         <valid characters>
                space        <space characters>
                special      <special characters>
                upper        <upper-case characters>
                xdigit       <hexadecimal characters>


~

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3