0% found this document useful (0 votes)
11 views19 pages

OS Filters 2

The document provides an overview of filters in Linux, which are commands that process input from standard input and produce output to standard output, primarily for text processing. It details common filter commands such as cat, head, tail, sort, cut, uniq, tr, and grep, along with their syntax and usage. Additionally, it explains Basic and Extended Regular Expressions (BRE and ERE) used for pattern matching in text processing tools.

Uploaded by

SHADOW GAMING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views19 pages

OS Filters 2

The document provides an overview of filters in Linux, which are commands that process input from standard input and produce output to standard output, primarily for text processing. It details common filter commands such as cat, head, tail, sort, cut, uniq, tr, and grep, along with their syntax and usage. Additionally, it explains Basic and Extended Regular Expressions (BRE and ERE) used for pattern matching in text processing tools.

Uploaded by

SHADOW GAMING
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 19

Filters in Linux

Subject Code:MCA13

Dr Manjunath M Mrs. Komala R


Assistant Professor Assistant Professor
Department of MCA Department of MCA
M SRamaiah Institute of Technology (MSRIT) M S Ramaiah Institute of Technology (MSRIT)
Bangalore - 560054 Bangalore - 560054
Filters

Filters are the set of commands that take input from standard input stream i.e.
stdin, perform some operations and write output to standard output stream
i.e. stdout.

Filters in Unix are commands that take input, process it, and produce output,

Filters typically used for text processing.

They read data from standard input (stdin), perform some transformation, and
output the modified data to standard output (stdout).

Common filter commands are
– cat
– cut
– head
– tail
– sort
– Uniq
– tr
cat command

The cat (concatenate) command is used to view, combine, and create files.

Syntax:
– cat [options] filename
head command

The head command is used to display the first few lines or bytes of a file.

It is useful for quickly viewing the beginning of large text files.

Syntax:
– head [OPTION]... [FILE]...
tail command

The tail command is used to display the last few lines or bytes of a file.

It is useful for viewing logs, real-time updates, and recent data.

Syntax:
– tail [OPTION]... [FILE]...
sort command

The sort command is used to arrange lines in text files in a specific order.

Syntax:
– tail [OPTION]... [FILE]...
cut command

The cut command in Unix is used to extract specific sections of each line from a file or
standard input.

It is commonly used for text processing and works by selecting portions of data based on
bytes, characters, or fields.

Syntax:
– cut [options] filename
pr command

The pr command in Linux is used to format text files for printing.

It adds headers, footers, page breaks, columns, and more to make output look structured
when printed.

Syntax:
– pr [options] [file]
paste command

The paste command in Linux is used to merge lines of files horizontally (side by side) by
joining them column-wise.

Syntax:
– paste [options] file1 file2 ...
uniq command

The uniq command in Linux is used to filter out adjacent duplicate lines from a sorted
file or input.

It helps in detecting and removing consecutive duplicate entries while keeping the first
occurrence.

Syntax: uniq [options] file1
uniq command
tr command

The tr (translate) command in Linux is used for text transformation by replacing,
deleting, or compressing characters from standard input (stdin).

Syntax:
– tr [OPTION] SET1 [SET2]
grep command

The grep stands for Global Regular Expression Print

The grep command in Linux is used to search for specific text or patterns in files or
input streams.

Syntax:
– grep [OPTIONS] PATTERN [FILE]

Example:
– grep -c "hello" file.txt
grep command
Basic Regular Expression (BRE)

Basic Regular Expression (BRE)



Basic Regular Expressions (BRE) are a set of pattern-matching rules used in text
processing tools like grep, sed, awk, and vi in Linux.

They allow searching and manipulating text based on specific character patterns.

Used for searching, filtering, and text manipulation in command-line tools.

Example: grep "pattern" file.txt searches for "pattern" in file.txt.

BRE supports character classes, anchors, repetition, and grouping to match specific text
patterns.

Common Operators in BRE
➢ ^ → Matches the beginning of a line.
➢ $ → Matches the end of a line.
➢ * → Matches zero or more occurrences of the preceding character.
➢ . → Matches any single character.
➢ [abc] → Matches any one of "a", "b", or "c".
➢ [^abc] → Matches any character except "a", "b", or "c".
BRE command
Extended Regular Expression (ERE)

Extended Regular Expression (ERE)


Extended Regular Expressions (ERE) introduce several enhancements over Basic
Regular Expressions (BRE) that facilitate more powerful and flexible pattern matching
without the verbose syntax often required in BRE.


The primary enhancements of ERE over BRE involve adding syntactic sugar (e.g., +, ?,
and |) that reduces the need for escaping and simplifies expressions.


ERE also typically processes patterns slightly faster due to their optimized handling of
these expressions.


These features make ERE particularly useful for complex pattern matching tasks in scripts
and command-line operations where readability and efficiency are crucial.
RE command
End of the Presentation

You might also like