A filter is a UNIX command which which will extract(select) some data from a given text file. The following are some of the filters available in UNIX
i)uniq ii) grep iii)cut iv) paste v) join vi)
i) uniq command:
This command line displays unique lines from the given file i.e., if two successive lines are same in a file then duplicate lines will be removed.
/netsem2014/anil/~ cat>sample.txt
hi how are you
hi where are you
hi where are you
bye take care.
/netsem2014/anil/~ uniq -c sample.txt
hi how are you
hi where are you
bye take care.
grep command:
This command is used to select lines from a file having some specified string.
/nesem2014/anil/~ cat>sample.txt
hi how are you?
who are you?
welcome here.
bye take care.
/netsem2014/anil/~ grep "are" sample.txt
(the above command combination displays the lines containing are)
hi how are you?
who are you?
/netsem2014/anil/~ grep "^who" sample.txt
(the above command combination displays the lines which starts with string hi)
/netsem2014/anil/~ grep "you$" sample.txt
(the above command combination displays the lines which ends with you)
hi how are you?
who are you?
/netsem2014/anil/~ grep -n "hi" sample.txt
(the above command combination displays those lines having string hi along with their line numbers)
/netsem2014/anil/~ grep -v "hi" sample.txt
(the above command combination displays those lines that not containing hi)
welcome here
bye tc
cut command:
This command is used to cut some words from the given line or file.
/netsem2014/anil/~ cat>sample.txt
hi how are you
UNIX is a multi user operating system
bye take care.
/netsem2014/anil/~ cut -f1,2 sample.txt
(the above command combination displays first and second word of each file in a given file)
hi how
UNIX is
bye take
/netsem2014/anil/~ cut -c 4 sample.txt
(the above command combination displays fourth character of each line in a given file)
h
X
paste command:
This command is used to join the files vertically
/netsem2014/anil/~ cat>sample1.txt
hi how are you?
/netsem2014/anil/~ cat>sample2.txt
where are you?
/netsem2014/anil/~ paste sample1 sample2>sample3
/netsem2104/anil/~ cat>sample3
hi how are you?
where are you?
filters in linux, cut command, paste command, join command,awk,sed command, grep command, egrep, fgrep,
No comments:
Post a Comment