Uncategorized

BASIC LINUX COMMANDS FOR TEXT MANIPULATION

Hello Linux folks, In this blog I’ll tell you about some basic Linux text manipulation commands.

1: echo

The echo command is used to display a line of text to the standard output(stdout).

2: printf

The printf command is used to format and print data to the standard output.

3: cat

Cat is used to concatenate files and print their contents to standard output. In other words, it simply displays the contents of a file.

You know there is a modern version of cat (batcat) with syntax highlighting.

4: tac

The tac command, like the cat command, concatenates and prints file contents in reverse order. The name suggests that this command is the inverse of the popular cat command.

5: paste


The paste command, like the cat command, merges lines in a file into a single large line.

6: head


This command shows the first section of a file. Assume we have a lengthy file and you only want to see the first few lines. This is where the head command comes in; the head command, by default, displays the first 10 lines of a file.

If you only want to see the first 5 lines.

7: tail

The tail command, like the head command, displays the last 10 lines of a file by default. However, you can change it and specify the number of lines to display. I’ve chosen to show the last 5 lines in this case.

8: rev

This command reverses lines characterwise.

9: sort


The sort command is very useful for sorting files, and text lines.

The sort command also has the capability of sorting in reverse order by using its -r option.

you can use the sort command to remove repeated lines, resulting in only unique lines. This is done by using the sort command with -u option.

10: wc

Word Count (wc) prints the number of lines, words, and bytes respectively in each file.

You can also specify what you want to display by using the l-, -w, or -c options, which will display the number of lines, words, or characters (bytes) respectively.

11: nl

The nl (number lines) is another command It displays the contents of a file as well as line numbers.

12: grep

The grep command is one of the most common text processing commands you will use. It allows you to search files for characters that match a certain pattern.