How to filter lowercase or uppercase words/letters from a file in Linux ?
Today we will look how to filter lowercase or uppercase letters/words from a file or string in Linux.
The easiest way to achieve this task is to use tr command with few options.
Create a new test file with lowercase and uppercase characters
[root@ngelinux ~]# cat testfile2 hello HOW are YOU. WELCOME to NGELinux.com [root@ngelinux ~]#
1. Filter lowercase characters
[root@ngelinux ~]# cat testfile2 | tr -d [:upper:] hello are . to inux.com
2. Filter uppercase characters.
[root@ngelinux ~]# cat testfile2 | tr -d [:lower:] HOW YOU. WELCOME NGEL. [root@ngelinux ~]#
Hence we can see the usage of [:upper:] and [:lower:] options with tr command.
The above tip is very useful for string manipulation on linux.