Presentation is loading. Please wait.

Presentation is loading. Please wait.

CS 497C – Introduction to UNIX Lecture 23: - Simple Filters Chin-Chih Chang

Similar presentations


Presentation on theme: "CS 497C – Introduction to UNIX Lecture 23: - Simple Filters Chin-Chih Chang"— Presentation transcript:

1 CS 497C – Introduction to UNIX Lecture 23: - Simple Filters Chin-Chih Chang chang@cs.twsu.edu chang@cs.twsu.edu

2 more: Paging Output UNIX offers two pagers: more and less. To view the file chap1, use more chap1. more is a pager that shows output of a file at a time. You can scroll both forward (f) and backward (b). You can search for a pattern ( /pattern ). The pattern can be both a simple string as well as a regular expression. /[sS]ystem matches two strings.

3 more: Paging Output /^# matches the line beginning with #. You can repeat the last command with a dot. You can switch to the next file ( n ) or previous file ( p ) with multiple files. more is often used in a pipeline such as: ls -l | more You can use the help facility by hitting h. You can also invoke the vi editor directly from the pager ( v ).

4 wc: Line, Word and Character Counting wc counts the number of lines, words and characters. You can use wc with options to specify count. The -l option counts only the number of line. The -w and -c options count words and characters respectively. When used with multiple files, it prints a total of everything. wc can be used a filter to count lines and words in the standard output.

5 od: Displaying Data in Octal od displays the octal value of a character, and is used to display invisible characters. When used with the -bc options, it shows you the escape sequences \f (formfeed), \n (newline), and \t (tab). od –bc odfile You can use od to find out the nonpritable character in the filename. ls P* | od -bc

6 pr: Paginating Files The pr command prepares a file for printing by adding suitable headers, footers, and formatted text. It is mostly used in conjunction with the lpr (lp) command. pr program.c | lpr The -l (length) option is used to specify a different page size.

7 pr: Paginating Files The output can be double-spaced (-d), printed in multiple columns (-k), and set to start from a specific page number (+k). The –t option removes all headers. The following command format output in two columns without any header. pr -t -2 group

8 cmp: Comparing Two Files There are three file comparison utilities in the UNIX system: cmp, diff, and comm. The cmp (compare) command tells you where the first difference was encountered. The -l (list) option gives a detailed character-for-character listing. You can use cmp in a pipeline to count the number of differences between two files: cmp -l group? | wc -l

9 diff: Converting one File to Another The diff command shows the differing lines, using a set of instructions which, when applied to one file, converts it to the other. Each instruction is applied to the first file and comprises an address and an action. The instruction 3c3 indicates the change of line 3 in both files. 7a8 means appending a line after 7, yielding line 8 in the second file. 5, 6c changes two lines.


Download ppt "CS 497C – Introduction to UNIX Lecture 23: - Simple Filters Chin-Chih Chang"

Similar presentations


Ads by Google