GTU OS Program - 11 Filters

11. Shell programming using filters (including grep, egrep, fgrep).

The programs that take plain text as standard input and transforms it into a meaningful format, and then returns it as a standard output is known as Filters.

Some of the most commonly used filters are explained below:

  1. cat
  2. head
  3. tail
  4. sort
  5. uniq
  6. wc
  7. grep
  8. tac
  9. sed
  10. nl

1. cat: Displays the text of the file line by line.

Syntax
cat [path]
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

2. head: Displays the first n lines of the specified text files. If the number of lines is not specified then by default prints first 10 lines.

Syntax
 head [-number_of_lines_to_print] [path]
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

3. tail: It works the same way as head, but in reverse order. It returns the lines from bottom to up

Syntax
tail [-number_of_lines_to_print] [path] 
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

4. sort: sorts the lines alphabetically by default but we can customize the way of sorting.

Syntax
sort [-options] [path]
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

5. uniq: removes duplicate lines. it has a limitations that it can only remove continuous duplicate lines.

Syntax
uniq [options] [path]

6. wc: It gives the number of lines, words and characters in the data.

Syntax
 wc [-options] [path]
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

wc gives 4 outputs as

  • number of lines
  • Number of words
  • Number of characters
  • path

7. grep: grep is used to search a particular information from a text file.

Syntax
grep [options] pattern [path]
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

8. tac: It is just reverse of cat command. It prints from bottom to top.

Syntax
tac [path]
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

9. Sed: It stands for stream editor. It allows us to apply search and replace operation on our data effectively.

Syntax
sed [path]

The expression we have used below is of the form 's/search/replace/g'

Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

In the above output we replaced cat with the text "this is replaced text"

10. nl: It is used to number the lines of our text data.

Syntax
nl [-options] [path] 
Output
Gtu study material for engineering students gtu material gtu info filers in Unix/linux

gtu os lab manual,

os GTU Practical,

operating system Programs,

Operating system shellscript programs,

Gtu study material 3140705,

OS 3140702,

os practical list,

shell script programming,

Shell programming using filters (including grep, egrep, fgrep)

Comments

YouTube

Popular posts from this blog

GTU OOP Program - 18

GTU OS Program - 7

GTU OS Program - 3