Download presentation
Presentation is loading. Please wait.
Published byRoland Copeland Modified over 9 years ago
1
Chapter 10 Advanced File Processing
2
Regular Expressions A compact notation for representing patterns in strings Used by many common Linux utilities such as: – less/more – ed – vi – emacs – egrep – grep – fgrep – awk – sed – lex – perl – python
3
Table 10.1 Regular Expression Operators
4
Table 10.1 More Regular Expression Operators
5
Regular Expression Examples cat|dog matches "cat" or "dog“..at matches any three-character string ending with "at", including "hat", "cat", and "bat". [hc]at matches "hat" and "cat". [^b]atmatches all strings matched by.at except "bat". ^[hc]at matches "hat" and "cat", but only at the beginning of the string or line. [hc]at$matches "hat" and "cat", but only at the end of the string or line.
6
Regular Expression Examples (0|1)+ 1+0* a*ba*ba* [A-Za-z][A-Za-z0-9]* (yaba|daba)+doo
7
Table 10.2 Examples of Regular Expressions for vi and Their Meaning
8
Table 10.3 Some Commonly Used vi Commands Illustrating the Use of Regular Expressions
9
File Compression compress uncompress gzip gunzip gzexe zcat zmore uuencode uudecode
10
Figure 10.1 The process of uuencoding and uudecoding
11
The Sort Utility Sorts lines of ASCII text Options for: – Ascending/descending order – Case folding – Ignoring leading whitespace – Alpha/numeric – Multiple keys
12
sort - sort lines of text files Syntax sort [OPTION]... [FILE]... Options -b, --ignore-leading-blanks ignore leading blanks -d, --dictionary-order consider only blanks and alphanumeric characters -f, --ignore-case fold lower case to upper case characters -i, --ignore-nonprinting consider only printable characters -n, --numeric-sort compare according to string numerical value -r, --reverse reverse the result of comparisons Other options: -k, --key=POS1[,POS2] start a key at POS1, end it at POS2 (origin 1) -t, --field-separator=SEP use SEP instead of non-blank to blank transition
13
Sort examples File donors.dat Bay Ching 500000 China Jack Arta 250000 Indonesia Cruella Lumper 725000 Malaysia sort donors.dat Bay Ching 500000 China Cruella Lumper 725000 Malaysia Jack Arta 250000 Indonesia
14
Sort Example – by last name sort +1 donors.dat Jack Arta 250000 Indonesia Bay Ching 500000 China Cruella Lumper 725000 Malaysia
15
Sort Example – by donation amount sort +2 donors.dat Jack Arta 250000 Indonesia Bay Ching 500000 China Cruella Lumper 725000 Malaysia sort +2 -n donors.dat Jack Arta 250000 Indonesia Bay Ching 500000 China Cruella Lumper 725000 Malaysia sort +2 -n -r donors.dat Cruella Lumper 725000 Malaysia Bay Ching 500000 China Jack Arta 250000 Indonesia
16
Locating Files find whereis which
17
Find command Syntax Find directory-list expression Searches directory-list for files that match conditions in expression Can find files by name, owner, permission, size, age, links
18
Find Command Examples find ~ -name *.gif -print find / -name socket.h -print find / -size+5000000c -print find ~ -newer filetocompare
19
Searching File Contents grep egrep fgrep
20
Grep – Get Regular Expression & Print Syntax grep [options] pattern [file-list] Searches files in file-list, prints lines which match the given pattern Options to fold case, print line #’s, filenames, non- matching lines fgrep – faster but dumb egrep – slower but more powerful
21
Command History A list of the recently used commands is maintained and controlled by the variables: – HISTSIZE – HISTFILE – HISTFILESIZE
22
Table 10.4 Commonly Used Event Designators for History Expansion
23
Table 10.5 Commonly Used Event Designators for History Expansion
25
Table 10.6 Commonly Used Modifiers for History Expansion
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.