How to filters command in linux systems

Linux Filter commands accept input data from stdin (standard input) and produce output on stdout (standard output). It transforms plain-text data into a meaningful way and can be used with pipes to perform higher operations.

These filters are very small programs that are designed for a specific function which can be used as building blocks.

Linux Filter Commands Options :

cat
cut
grep
comm
sed
tee
tr
uniq
wc
od
sort
gzip

Now we will discussion all filters command with all other options below. Please practice with your own ability for your expertness.

Linux Cat Filters descriptions

When cat command is used inside pipes, it does nothing except moving stdin to stout.

Sample syntax of cat command :

# cat<filename>| cat or tac | cat or tac |. . .

Like example of cat command :

#cat weeks.txt | tac | cat | cat | tac

See your terminal after run the command, output of one ‘cat’ or ‘tac’ command is passing onto another as input.

Linux cut Filters descriptions

Unix or Linux cut command is useful in selecting a specific column of a file. After (-d), delimiter (from where you want to separate the columns) comes. Delimiters can be a space (‘ ‘), a hyphen (-), a slash (/) or anything else. After (-f), column number is mentioned.

Sample syntax of cut command :

# cut -d(delimiter) -f(column Number) <filename>

Hyphen (-) As Delimiter

Sample syntax of cut command :

# cut -d- -f(column Number) <filename>

Like example of cut command :

# cut -d- -f2 test
# cut -d- -f1 test

See your terminal after run the command, our delimiter is hyphen (-), hence we have used (-) after (-d). Linux “cut -d- -f1 marks.txt” command displays column 1 and command “cut -d- -f2 marks.txt” displays column 2.

Space As Delimiter

If you want to use space as a delimiter then you have to quote the space (‘ ‘).

Sample syntax of cut with ‘ ‘ qutetion command :

# cut -d ‘ ‘ -f(column Number)

Like example of cut (‘ ‘) command :

#cut -d ' ' -f2 test  
#cut -d ' ' -f5 test  
#cut -d ' ' -f3 test  

Look at the above snapshot, our delimiter is space, hence we have used (‘ ‘) after (-d). Linux cut -d ‘ ‘ -f2 test command displays column 2, command “cut -d ‘ ‘-f5 test” displays column 5 and command “cut -d ‘ ‘-f3 test” displays column 3

Leave a Reply