Unit 3 Text Processing and System Configuration tools.

Презентация:



Advertisements
Похожие презентации
Standard I/O and Pipes. Standard Input and Output Linux provides three I/O channels to Programs Standard input (STDIN) - keyboard by default Standard.
Advertisements

Running Commands & Getting Help. Running Commands Commands have the following syntax: command options arguments Each item is separated by a space Options.
Unit 2 Users Management. Users Every user is assigned a unique User ID number (UID) UID 0 identifies root User accounts normally start at UID 500 Users'
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Policy Controls Applying Route-Maps as BGP Filters.
Using Bash Shell. Command Line Shortcuts File Globbing Globbing is wildcard expansion: * - matches zero or more characters ? - matches any single character.
Week Finding and Processing files 2 locate Queries a pre-built database of paths to files on the system Database must be updated by administrator.
Week -9 vim contd.. and System Configuration tools.
Loader Design Options Linkage Editors Dynamic Linking Bootstrap Loaders.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Route Selection Using Policy Controls Employing AS-Path Filters.
S5-1 PAT328, Section 5, September 2004 Copyright 2004 MSC.Software Corporation SECTION 5 RESULTS TITLE EDITOR.
Using Dreamweaver MX Slide 1 Window menu Manage Sites… Window menu Manage Sites… 2 2 Open Dreamweaver 1 1 Set up a website folder (1). Click New…
© 2005 Cisco Systems, Inc. All rights reserved.INTRO v Module Summary The Cisco Discovery Protocol is an information-gathering tool used by network.
© 2006 Cisco Systems, Inc. All rights reserved. CVOICE v Configuring Voice Networks Configuring Dial Peers.
© 2006 Cisco Systems, Inc. All rights reserved. CIPT1 v Deployment of Cisco Unified CallManager Release 5.0 Endpoints Managing Endpoints with Cisco.
PAT312, Section 21, December 2006 S21-1 Copyright 2007 MSC.Software Corporation SECTION 21 GROUPS.
© 2006 Cisco Systems, Inc. All rights reserved. MPLS v MPLS VPN Implementation Configuring VRF Tables.
© 2006 Cisco Systems, Inc. All rights reserved. MPLS v Complex MPLS VPNs Introducing Central Services VPNs.
Sequences Sequences are patterns. Each pattern or number in a sequence is called a term. The number at the start is called the first term. The term-to-term.
© 2005 Cisco Systems, Inc. All rights reserved. BGP v Optimizing BGP Scalability Implementing BGP Peer Groups.
Click to add title Template for Microsoft PowerPoint.
Транксрипт:

Unit 3 Text Processing and System Configuration tools

Week -7 Text Processing Tools

Tools for Extracting Text File Contents: less and cat File Excerpts: head and tail Extract by Column or Field: cut Extract by Keyword: grep

Viewing File Contents cat: dump one or more files to STDOUT Multiple files are concatenated together less: view file or STDIN one page at a time Useful commands while viewing: /text searches for text n/N jumps to next/previous match v opens the file in a text editor less is the pager used by man

Some useful options to use with cat -A: Show all characters, including control characters and non-printing characters -s: Squeeze multiple adjacent blank lines into single blank line -b: Number each(non-blank) line of output Viewing File Excerpts head: Display the first 10 lines of a file tail: Display the last 10 lines of a file Use –n to change number of lines displayed Use –f to follow subsequent additions to the file Very useful for monitoring log files

Extracting text by keyword - grep Print lines of files or STDIN where a pattern is matched $grep john /etc/passwd $date –help | grep year Use –i to search case-insensitively Use –n to print line numbers of matches Use –v to print lines not containing pattern Use –Ax to include x lines after each match Use –Bx to include x lines before each match Use –r to recursively search a directory Use –color=auto to highlight the match in color

Extracting text by column or field - cut Display specific columns or file or STDIN data $cut –d: -f1 /etc/passwd $grep root /etc/passwd | cut –d: -f7 Use –d to specify the column identifier Use –f to specify the column to print Use –c to cut by characters $cut –c2-5 /usr/share/dict/words

Tools for Analyzing text Text Stats: wc Sorting Text: sort Comparing files: diff and patch Spell check: aspell

Gathering Text Statistics – wc Counts words, lines, bytes and characters Can act upon a file or STDIN $wc a.txt Use –l for only line count Use –w for only word count Use –c for only byte count Use –m for character count

Sorting Text Sorts text to STDOUT – original file unchanged $sort [options] file(s) Common Options -r performs a reverse -n performs a numeric sort -f ignores (folds) case of characters in strings -u (unique) removes duplicate lines in output -t c uses c as a field separator -k x sorts by c-delimited field x Can be used multiple times

Eliminating duplicate lines sort –u: removes duplicate lines from input uniq: removes duplicate adjacent lines from input Use –c to count number of occurences Use with sort for best effect: $sort userlist.txt | uniq -c

Comparing files - diff Compares two files for differences $diff foo.conf-broken foo.conf-works 5c5 <use_widgets = no --- >use_widgets = yes Denotes a difference (change) on line 5 Use gvimdiff for graphical diff Provided by vim-x11 package

Duplicating file changes - patch diff output stored in a file is called a patchfile Use –u for unified diff, best in patchfiles patch duplicates changes in other files (use with care) Use –b to automatically back up changed files $diff –u foo.conf-broken foo-conf-works > foo.patch $ patch-b foo.conf-broken foo.patch

Spell checking with aspell Interactively spell-check files: $aspell check letter.txt Non-interactively list mis-spelled words in STDIN $aspell list<letter.txt $aspell list<letter.txt | wc -1