Linux Filters
Linux Filters
FILTERS
• Linux Filter commands accept input data from stdin (standard input) and produce
• It transforms plain-text data into a meaningful way and can be used with pipes to
• -b
- omits line numbers for blank spaces
• -e or –E
- displays $ at the end of each line prior to net line
• -n
- displays line numbers
• -s
- if the o/p has multiple lines , it replaces with one empty line.
TAIL
• This command is reverse of TAIL command it prints the first few lines of files
by default n value is 10
This command writes the output both to the file and to the screen.
-It basically do not overwrite the file but append to the given file.
• It is used for ordering of file ,sorts the context of the files line by line
• Line starting with number appears before the line starting with alphabet.
•It is a text processing command used to extract portion of text from a file by
selecting columns or fields.
•To extract only a desired column from a file, use -c option
$ cut –c 2 filename
•Range of characters can also be extracted by specifying start and end
positions delimited with ‘-’
$ cut –c 1-3 filename
$ cut –c 4- filename(starts from 4th position to end of the line)
$ cut –c -8 filename(ends at 8th position)
• To extract the specific bytes, you need to follow -b option with the list of byte
-List without ranges
$ cut -b 1,2,3 filename.txt
-List with ranges
$ cut -b 1-3,5-7 filename.txt
• cut uses tab as a default field delimiter but can also work with other delimiter by
using -d option
EX:
$ cut -d " " -f 1 filename.txt
-here it is considered space as a field separator or delimiter
PASTE
• The grep filter searches a file for a particular pattern of characters, and displays all lines that
contain that pattern.
• Syntax : grep [options] pattern [files]
Options:
-c : This prints only a count of the lines that match a pattern
-h : Display the matched lines, but do not display the filenames.
-i : Ignores, case for matching
-l : Displays list of a filenames only.
-n : Display the matched lines and their line numbers.
-v : This prints out all the lines that do not matches the pattern
-r : recursive search
• To count the number of matches
grep –c “pattern“ filename
• Displays only the filenames which matches the given pattern
grep –I “string“ filename
grep –rI “string“ filename (exact match)
grep –rIw “string“ filename (exact word)
grep –rIwb “string“ filename (exact position)
Thank You!*