LPI 010-150 – Text Processing Tools

  1. Concatinating Files

The Cat command is one of the most universal tools. All it does is copy standard input to standard output in combination with the shell. This can be very powerful. You can use Cat to display the content of a file. For example cat attcut resolve it will display the content of attic resolveconf file. And we can use Cat to cool Cat in a file into a bigger file. For example, we have here part one file. It contains one line and if we get part two, it will display two and if we get part three, it will display three. So each file has specific content part one and part two and part three. We can display the content of all files using Cat. For example Cat part one, part two, part three and we can call Cat init all these files into a bigger file. So we can use Cat part one, part two, part three and redirect the output to for example file called all. So if we get all, we will see the content of the three files in one file.

You can use Cat to create flat text files. Just type Cat Greeter then sign test file, then press Enter. After that we can write anything such as this is test file and press Enter. To exit from Cad prompt we will press CTRL z command. Now if we can test the test file, we will see the line which has been written before. So control the key combination will send end of file to the running process ending the cat command. We can use Cat to copy files. For example, we can get test tickets file and redirect the output to for example test to dot tickets file. So if we get test to dot tickets, we will see that it has the same content of test tickets file. Let’s clear the screen using clear command tag command tag command is the reverse of Cat. For example, if we type text followed by all file, we will see that the output has been reversed. So if we use cat with the same file, we will see that this is the normal output of the old text file.

  1. View File Contents

The list command is useful for displaying files that take up more than one screen. List will allow you to see the contents of the file page by page. For example, if we type list big file tickets we will see that big file dot tickets will be displayed page per page and to go to the next page we will press space bar and we can navigate also using up arrow and down arrow and we can search for specific string. When we press forward slash and write the string which we need to search for notice here it will display that we will search for root string. If we press Enter we will get the result by default the search direction will be from up to down direction and to continue to search in the same direction we will press in small and to search in the opposite direction we will press in Capital. To exit from this page we will press Q. We can use more big file text to display this file page page and we can use the space bar to see the next page and queue to quit. Some people prefer the less command to more command.

  1. Viewing File Excerpts

Now let’s see how to look at the contents of the tickets files. You can use head command to display the fairest ten lines of the tickets file. For example, attic password. And we can display the first four lines from the same file using four of option similar to head. Detail command will display the last ten lines of a file such as ATC password file. And if we need to display the last three lines, we can use three option.

  1. Extracting Text by Keyword

The Grip filter is famous among Unix and Linux users. The most common use of Grip is to filter lines of text containing or not containing a certain string. For example, we have fire called tennis in our home directory and it has three lions. Mustafa C in Coma Cairo in capital letter Nile Linux coma Cairo in small letter and welcome to Linux is in small letter. So if we get tennis file and then pipe space Grip Cairo it will display the lines which have cairo string.

We can write this without the cat command, so we can type Grab Cairo then the ticket file which is tennis tickets it will display the same result. One of the most useful options of Grebe is Grebe Oi which filters in a case in sensitive way. It means it will display Cairo even if it’s in capital or small letter. So let’s try Greb I Cairo Tennis, Texas it will display two lines mustafa C in Coma Cairo and the Cairo here is in capital letters and the second line my Linux Coma Cairo and the Cairo here is in small letters because we are using I option. Another very useful option is Gripv which outputs lines not matching the string.

For example, if we grip V Cairo Tennis tickets it will display all lines except the line which has cairo in a small letter. If we add I option it will display only one line which has not Cairo as a string. If we take another example, let’s say Grip VI Linux it will display all lines which do not have Linux string for both capital and small letters. Because we are using dashi option.

  1. Extracting Text by Column or Field

The Cut filter can select columns from files depending on the delimiter or the counts of pipes. So if we use for example cut G which defines the diameter in our file which is the test file, the diameter between the columns is column. So we will use D to define the delimiter as colon. Then we will select F for field one comma three followed by the file name. This command will display the column number one and the column number three from this file which is the test file. So here we can see this is the column number one and this is the column number three.

And here the column is the delimiter between the fields. When using a space as the delimiter for cut you have to quote the spaces. For example we can use cut g for diameter and between two double quotes we will put space. then F to define the selected fields. For example one from file zero one here it will display only the first field of the file zero one. If we get file zero one we will see that the space is the delimiter between the failures of the file zero one we can use cut to display the second to the 7th character of test file.

For example, if we type cut C for character to the second character seven to 7th character from our file which is test file, we will see that this command will display only the second to the 7th character from test file. Notice that Cut will not modify the content of the file, it’s only filter the contents of the files and display it in the standard output which is our terminal or the screen. So if we can for example test we will see test as it is without any modification. And if we get file zero one we will see that file is the original without any modification.

  1. Sorting Text

The sort command by default will do alphabetical sort for specific file. So if we type sort file one here, it will display the contents of file zero one in alphabetical sort based on the first column. If we need to sort based on the second column, we can do sort K two. It means it will sort based on the second column. So here it’s sort the content of the file in alphabetical sort based on the second column. If we need to sort based on the third column, which is numeric column, we can use sort K three, which is the third column, and N for numerical sort. Here we can see that the content of file zero one has been sorted based on the third column, which is numerous numeric column. Sort command will not modify the contents of file zero one. So if we get file zero one we will see the original content as it is. But sort command will sort the content of the file and display it in the standard output, which is the terminal or the screen.

  1. Text Stats

WC Command will count words, lines and characters in a specific file. So if we type WC file zero one, it will display that we have five lines, 15 words and 64 characters. If we get file zero one, we will see that the contents of file zero one. If we need to count the lines, we can execute WC l file one here, it will display that we have five lines in file one. If we need to count the words, we can use WCW file one here, it will display that we have 15 words. If we need to count the characters, we can use WC C file zero one. It will display the number of characters in the file. File zero one.

img