Presentation is loading. Please wait.

Presentation is loading. Please wait.

CSC 4630 Meeting 2 January 22, 2007. Filters Definition: A filter is a program that takes a text file as an input and produces a text file as an output.

Similar presentations


Presentation on theme: "CSC 4630 Meeting 2 January 22, 2007. Filters Definition: A filter is a program that takes a text file as an input and produces a text file as an output."— Presentation transcript:

1 CSC 4630 Meeting 2 January 22, 2007

2 Filters Definition: A filter is a program that takes a text file as an input and produces a text file as an output. UNIX context –Write filters to use stdin as the input file and stdout as the output file. –Use pipe to connect filters. Notation is the vertical bar |

3 Filter History Originally conceived by M. D. McIlroy in the early 1970’s The UNIX notation for pipeline, the vertical bar, was introduced by K. L. Thompson. –“The Unix time-sharing system,” Comm. ACM, July 1974. –“The Unix programming environment,” Software Practice and Experience, January 1979.

4 Filter Examples detab -- replaces tab characters in a text file with the appropriate number of space characters entab -- replaces long strings of space characters with the appropriate number of tab characters compress – replaces long strings of the same character with a coding for the string and its length

5 Filter Examples (2) expand -- reverses the action of the compress filter translit – in simplest form, takes two argument strings of equal length and changes all occurrences of elements of first string into corresponding elements of second string. –Example: translit abc xyz changes all a’s to x’s, b’s to y’s and c’s to z’s.

6 Simple Filters: head and tail Use head to look at the first few lines of a file –Keeps the first n lines of input and discards the rest head [-n] [file] Use tail to look at the last few lines of a file –Keeps the last n lines of input and discards the rest tail [-n] [file] –Discards the first n-1 lines of input and keeps the rest tail [+n] [file]

7 tr Command tr translates characters –Two arguments, given as strings –Three options, c d s –Often used for letter case conversion –Useful for “cleaning up” formatted output

8 tr Examples tr A-Z a-z Converts all upper case letters to lower case tr –s –tr –s ‘\033\010’ ‘\010\010’ tr –d ^Z –tr –d ‘\015\032’ tr –cs A-Za-z ‘\012’

9 tr Examples (2) tr a-b-d abcd tr a-c xyz tr -ac xyz tr \\ tr –c \ x tr \c x


Download ppt "CSC 4630 Meeting 2 January 22, 2007. Filters Definition: A filter is a program that takes a text file as an input and produces a text file as an output."

Similar presentations


Ads by Google