Download presentation
Presentation is loading. Please wait.
1
Chapter 6 Filters
2
Concept Of A Filter A filter is any command that gets its input from the standard input stream, manipulates the input, and sends the result to the standard output stream. Some filters can receive data directly from a file. The more command is a filter.
3
Using Filters with Pipes
Filters work naturally with pipes. A filter can be used on the left of a pipe, between two pipes, and on the right of a pipe.
4
The cat Command The cat command writes one or more input files one after another to standard output.
5
Using cat To Combine Files
6
Displaying a File with cat
7
Creating A File With cat
8
The head Command The head command copies N (10 by default) lines from the beginning of one or more files to standard output. If no files are specified, it gets the lines from standard input.
9
The tail Command The tail command outputs the data from the end of the file
10
The cut Command The purpose of cut is to extract one or more columns of data from standard input or one or more files.
11
Specifying Character Positions
We can use character option –c followed by one or more column specifications. A column specification can be one column or column range M – N , where M is the start column and N is the end column. Multiple columns are separated by commas. cut –c1-14,19-25 filename
12
Field Specification When data are separated by tabs, it is easier to use fields to extract the data from the file. Fields are separated by delimiters (the tab character by default). To specify the field, we use the field option –f. cut –f1,3-5
13
The paste Command Paste combines the first line of the first file with the first line of the second file and writes the result to standard output. It writes a tab between the columns and a new line character at the end of the last column. It continues with the next two lines.
14
The sort Command
15
Fields Within A Line
16
Field Specifier Examples
17
The tr Command The tr command replaces each character on a user-specified set of characters with a corresponding character in a second set tr “aeiou” “AEIOU”
18
The wc Command The wc command counts the number of characters, worlds, and lines in one or more documents.
19
The cmp Command The cmp command examines two file byte by byte.
It stops at the first byte that is different. For –s options no result is displayed, it can be determined by exit status echo $?
20
The diff Command The diff command shows the line by line differences between the two files.
21
The comm Command The comm command finds lines that are identical in two files. It displays the results in three columns: unique lines in file1, unique lines in file2, and common lines.
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.