FILTERS
A filter is a program that reads data from the output of another program or the standard input, processes it in some way, and sends the processed data to standard output or to another program.
There are many filters that are available in linux.
'wc' Command
'wc' stands for 'word count'. The 'wc' command counts the 'lines' , 'words' and 'characters' in a specified file.
Syntax : wc [options] [filename]
[user1 @linux-mac user1] $ wc names
1 5 22 names
Option Purpose
-c Prints only the character count
-w Prints only the word count
-l Prints only the line count
'sort' Command
The sort command arranges the output alphabetically.
Syntax : sort [options] [filename]
For example : Create a file called 'names' with the following names :
Shaffi
Candy
Ritu
Anubhav
[user1 @linux-mac user1] $ sort names
The output is :
Anubhav
Candy
Ritu
Shaffi
'sort is a very powerful command having many options.
'tail' Command
The 'tail' command prints the last 'n' lines of a specified file.
Syntax : tail [no. of lines] [filename]
[user1 @linux-mac user1] $ tail - 2 names
Ritu
Anubhav
The 'head' command is similar to the 'tail' command. It prints the first 'n' lines of the file.
'finger' Command
Syntax : finger [options] [user]
Linux is a multi - user system. That means more than one person can be logged in at any given time.
The finger command provides a lot of information about the users.
[user1 @linux-mac user1] $ finger
'find' Command
'Find' command search for the files or directories that match a given pattern.
Syntax : find [path] [expression]
[user1 @linux-mac user1] $ find/home/john-name "l*"
This will show all the fields and directories starting with name L
'diff' Command
The 'diff' command is used to find the difference between two files. This command displays the lines which are different.
Syntax : diff [first file name] [second file name]
For example : there are 2 files - test and exam.
Test contain "This is my test file"
Exam contain "This is my exam file"
[user1 @linux-mac user1] $ diff test exam
Output :
1c1
<This is my test file
-------
>This is my exam file
'comm' Command
Syntax : comm. [first filename] [second filename]
This command compares two files
E.G. First file name temp1 contains
A
B
C
D
Second file temp2 contain
A
B
X
Y
[user1 @linux-mac user1] $ comm temp1 temp2
Output :
A
B
C
D
X
Y
The 'comm' is the file comparison program which expects 2 file name as an input. It process the files received as input and display 3 column output. The 1st column gives the lines that are unique in the 1st file The 2nd column gives the lines that are unique in the 2nd file.
The 3rd column gives all lines that are common to all the files.
The 'TR' Command
This command is used to transfer or remove consecutive repeating characters from the characters in the input received by it.
Syntax : tr [options] [character to be looked for] [character to be translated into]
[user1 @linux-mac user1] $ tr a-z A-Z
hello
HELLO
'Cut' Command
The cut command is a filter that is used to vertically cut across columns to extract entire columns or specific number of characters.
Syntax : CUT[OPTIONS] [FILENAME]
[user1 @linux_max user1]$ cat>>data
charles 24 3243
carlton 22 442
tony 26 333
[user1 @linux_max user1]$ cut -d " " - f1,3<data
charles 3243
carlton 442
tony 333
[user1@linux_max user1]$
At the command prompt type the following ;
[user1 @linux_max user1]$ cut-3]<data
your screen would look like this ;
[user1 @linux_max user1]$ cut-3]<data
cha
car
ton
[user1 @linux_max user1]$
In above fig delimiter '' space has been specified and the first three character are selected from the file.
'Paste' Command :
The paste command works as the inverse of cut command. It is used to merge lines of files.
Syntax : PASTE[OPTIONS] [FILENAME]
For example : create a file named data :
[user1 @linux_max user1]$cat>>data
charles
carlton
tony
Now create a file named data1 :
cha
car
ton
AT THE COMMAND PROMPT TYPE THE FOLLOWING :
[user1 @linux_max user1]$cat data
charles
carlton
tony
[user1 @linux_max user1]$cat data
cha
car
ton
[user1 @linux_max user1]$ paste -d: data data1
charles:char
carlton:car
tony:ton
[user1 @linux_max user1]$
Using 'Pipes' :
Often we use output of one program as an input to another.we do so by using redirection operators >>.
Another and better method of performing the same is by a mechanism called 'pipes'. Pipe connects output of program to input of another program this concept is that of pipeline that connects two water tanks.
AT THE COMMAND PROMPT TYPE THE FOLLOWING :
[user1 @linux_max user1]$ 1s/more
The more command is a filter for paging through next one screen at a time. I he output of 1s is piped to more the more program ensures that we get the output one page at a time.
https://youtube.com/channel/UCLZqVRZUkuXIlST8BteqTig
This is the link of my YouTube please visit at this link and if you like it don't forget to like, share and subscribe the channel.
Your content is good but intent writing is not understandable so please improve this and I am from Quora
ReplyDelete