From that command, we will find two features described above. –I mean to ignore the case, wherever this keyword is used, the case affection is removed.
To fulfill the accomplishment of that feature’s functionality in the Linux operating system, we need to have a Linux OS installed. After configuration, you will provide the required user information, with the help of that the user will be logged in. Furthermore, when the username and password are provided, the user will be able to access all built-in features of the operating system. Finally, once the desktop is accessed, you are required to access the terminal, as commands have to be run on it.
In this example, we will see how grep helps in making use of avoiding case sensitivity. Consider a file named files11.txt. The file contains the following data in it; as you can see the word mango is written in different ways, some words are in uppercase and some are in lowercase. By using the cat command we will display the data of the file.
Once the command is used to display the data, it can be observed that the only word that matches the case of the letter present in the command is displayed. All letters are in lowercase.
Now to understand the concept of case insensitivity, we will use “-I” in the command to handle case-sensitivity by providing all the data present in the file, the matches with the string present inside the command.
From the output, you will come to know that all data that matches the word “mango” is displayed either with some words written in uppercase and some are in lowercase.
This example resembles the first one, the difference is that only a single word is obtained. This command helps in obtaining the whole string by matching it with the word provided in the command. Let us have a file filea.txt. as an example, we want to fetch a record according to the given match.
Now apply the same command to ignore the case and depict the output. The technical word is displayed by excluding the case to make it case-sensitive.
Another method of using grep to ignore case is to introduce a filename first and later apply the –I command with grep following “|” operator. Cat is used in conjunction with “|”. Let us have a file named file24.txt. as an example.
This command will fetch the word “Aqsa” in both upper and lower cases.
Moving towards another example. Here we will display the data of the file containing the word “my”. Here searching is done by introducing a directory thus command will sort the word in all files having the extension .txt in the system.
The above image shows the output obtained from the command. “my” word is highlighted, that is in both cases. Some files contain it in small letters while others have it in capital ones. The address of the files and file names are also displayed.
This example can be applied to the directory having all files present in it. Limitations will be applied to display the specific result that matched with the word we have defined in the command. “is” word is used for searching in all files present in the system.
The output shows whole strings containing the matched word in it. As “is” is written separately or combined within another word i.e. sister.
The next command shows how –iw works together in the command. Besides here, the search is through two words in a single file. The backslash and “|” are used to describe two words in a file while –w is used for the exact match of the respective word in the file.
$ grep ‘hamn\|house’ file21.txt
-I will ignore the case sensitivity. In the above example, we can see that the presence of –w with –I, allows a house in the first command not to be considered because –w allows the exact match. In the second command, we have removed both –iw, hence both words are displayed after matching in string.
More than one word is searched by applying a different method. Both words are searched from the same file these words are “job” and “earn”. Earn is fetched from the word learning as well take note that each word is separated from the keyword –e.
The above image shows the whole strings in a paragraph regarding the words present in the command. Like the above examples, -I have ignored all case discrimination of the words job and earn.
In this example, searching two words present in all files of the .txt extension. These two words are separated with –e, as –e is the right way for the separation of two words. The output obtained will have both words shown in all files of text extension. The whole address of the file is obtained and is displayed. –I will ignore the case sensitivity and will display both words present in all files.
In this guide, we have used the simplest example to elaborate on the concept of case sensitivity. We have tried our best to go through each aspect to enhance the knowledge regarding grep.