Text Processors Commands in Linux Distributions

Ömer Sevban Tümer
5 min readApr 23, 2024

Hi everyone! Today we will discuss about “Text Processors” which is big part of Linux System Administration. We will see how to use, play and customize according to our needs.

Okey, Let’s see..

What is Text Processors commands? Text Processors commands allow us to specifise an output of messages, texts, logs, and whatever.

You are Sysadmin and an application in server doesn’t work properly, or giving an error message.

You have a notebook with a thousand line and your need is only a word.

Text proccessors commands come up here! Here is main Text Processors;

We will discuss all with basic examples. Let’s begin..

I will use freepalestine file which contains “only” 20 children who is killed by Israel during genocide. Rest their soul.

cut command-

cut command is basically, is a command for cutting out the sections from each line of files and writing the result to standard output. cut command must contains a parameter. cut freepalestine does nothing. Take a look at the details.

Using -c1 parameter gives only first letter of them.

cut -c1,4,6,8 freepalestine

Seperated numbers with quotes gave this output.

cut -b1–3 freepalestine

-b parameter list by byte size.

Our file is weak to show -d and -f parameter. That’s why we will go /etc/passwd file.

/etc/passwd

Let’s list first 6th column seperated by “:”
cut -d: -f6 /etc/passwd

awk command-

Awk is a scripting language used for manipulating data and generating reports. The awk command programming language requires no compiling and allows the user to use variables, numeric functions, string functions, and logical operators.

What can we do with awk?

1. AWK Operations:
(a) Scans a file line by line
(b) Splits each input line into fields
(c) Compares input line/fields to pattern
(d) Performs action(s) on matched lines

2. Useful For:
(a) Transform data files
(b) Produce formatted reports

3. Programming Constructs:
(a) Format output lines
(b) Arithmetic and string operations
(c) Conditionals and loops

List 1st field of the file;

awk ‘{print $1}’ freepalestine

How to see these children’s age?

It’s possible with it: awk ‘{print $NF}’ freepalestine

Output

These are just a few of the ways to use. awk processor can use with different types, we can’t diversify here but, you should watch this video about awk processor. https://www.youtube.com/watch?v=0RZJsxHtPv4

grep command-

grep is used to search text and strings in a given file. In other words, grep command searches the given file for lines containing a match to the given strings or words. It is one of the most useful commands on Linux and Unix-like system for developers and sysadmins.

grep keyword file = Search for a keyword from a file
grep -c keyword file= Search for a keyword and count
grep -i KEYword file= Search for a keyword ignore case-sensitive
grep -n keyword file= Display the matched lines and their line numbers
grep -v keyword file= Display everything but keyword

All the output refer to grep is here.

sort and uniq commands-

Ordering and manipulating data in Linux-based text files can be carried out using the sort and uniq utilities. The sort command orders a list of items both alphabetically and numerically, whereas the uniq command removes adjacent duplicate lines in a list.

sort freepalestine

to reverse it

sort -r freepalestine

That’s it.

To show uniq command, i will add few lines.

Some lines have duplicated as you see. To remove duplicated lines, to remove it, we can use uniq processor.

Basicly, uniq freepalestine .

wc command-

wc stands for word count. As the name implies, it is mainly used for counting purpose.

wc filename = check file line count, word count and byte count

wc -l filename= get the number of lines in a file

wc -w filename = get the number of words in a file

Here’s a video I’m leaving here because the “sed” command, the only command missing from our table that I couldn’t add, is very comprehensive in scope;

https://www.youtube.com/watch?v=EACe7aiGczw

Thanks for reading, keep following!

--

--