10.
Examining File Contents <ul><li>head and tail commands: </li></ul><ul><ul><li>Display first few lines and last few lines of file </li></ul></ul><ul><ul><li>By default include 10 lines </li></ul></ul><ul><ul><li>-n option </li></ul></ul><ul><ul><ul><li>Specify number of lines </li></ul></ul></ul><ul><ul><li>Print output to STDOUT </li></ul></ul><ul><ul><ul><li>Redirect as needed </li></ul></ul></ul>

13.
Examining File Contents (continued) <ul><li>strings command </li></ul><ul><ul><li>Extracts text strings from file that includes binary and other non-text data </li></ul></ul><ul><ul><li>Provides convenient way to check for information that may not be otherwise available </li></ul></ul>

16.
Manipulating Text Files (continued) <ul><li>diff command </li></ul><ul><ul><li>Displays differences between two files </li></ul></ul><ul><ul><li>Output format: </li></ul></ul><ul><ul><ul><li>< indicates lines that were not found in second file </li></ul></ul></ul><ul><ul><ul><li>> indicates lines that were not found in first file </li></ul></ul></ul><ul><li>cmp command </li></ul><ul><ul><li>Gives quick check of whether two files are identical </li></ul></ul>

17.
Manipulating Text Files (continued) <ul><li>comm command </li></ul><ul><ul><li>Used to compare sorted files to see if they differ at all </li></ul></ul><ul><li>ispell spell checker </li></ul><ul><ul><li>Uses large dictionary to examine text file </li></ul></ul><ul><ul><li>Prompts with suggestions </li></ul></ul>

22.
Filtering and Editing Text with sed <ul><li>sed command </li></ul><ul><ul><li>Processes each line in text file according to series of command-line options </li></ul></ul><ul><ul><li>Example: </li></ul></ul><ul><ul><ul><li>sed -n '/lincoln/p' /tmp/names </li></ul></ul></ul><ul><ul><ul><li>Prints to screen all lines of /tmp/names file that contain text “lincoln” </li></ul></ul></ul><ul><ul><li>By default, prints each line to STDOUT </li></ul></ul>

23.
Filtering and Editing Text with sed (continued) <ul><li>Substitution command syntax: </li></ul><ul><ul><li>/pattern1/s/pattern2/pattern3/g </li></ul></ul><ul><ul><li>Watches for lines containing pattern1 </li></ul></ul><ul><ul><li>Replaces occurrences of pattern2 with pattern3 </li></ul></ul><ul><ul><li>g option at end of command </li></ul></ul><ul><ul><ul><li>Causes sed to replace all occurrences on each line </li></ul></ul></ul><ul><ul><ul><li>Means global </li></ul></ul></ul>

25.
Formatting with awk <ul><li>Processes text </li></ul><ul><ul><li>Extracts parts of file </li></ul></ul><ul><ul><li>Formats text according to information you provide on command line or in script file </li></ul></ul><ul><li>Format output based on fields within line of text </li></ul><ul><li>Often can perform same functions with sed or awk </li></ul>

29.
File Operations in vi <ul><li>:w command </li></ul><ul><ul><li>Write file you are editing </li></ul></ul><ul><li>:r file name </li></ul><ul><ul><li>Insert another file into file you are editing </li></ul></ul><ul><li>:q command </li></ul><ul><ul><li>Exit from vi </li></ul></ul><ul><li>:wq </li></ul><ul><ul><li>Save and exit </li></ul></ul>

30.
Screen Repositioning <ul><li>Line number and cursor position on line </li></ul><ul><ul><li>Shown at bottom right </li></ul></ul><ul><li>Use parentheses and curly braces </li></ul><ul><ul><li>Move forward or backward by one sentence or paragraph at a time </li></ul></ul><ul><li>Ctrl+f and Ctrl+b key combinations </li></ul><ul><ul><li>Move one screen forward and backward </li></ul></ul>

31.
Screen Repositioning (continued) <ul><li>Shift+G </li></ul><ul><ul><li>Take you to any line in file </li></ul></ul><ul><ul><li>Enter line number first then Shift+g </li></ul></ul><ul><li>Mark </li></ul><ul><ul><li>Like bookmark </li></ul></ul><ul><ul><li>m command followed by name (a-z and 0-9) </li></ul></ul><ul><ul><ul><li>Place mark </li></ul></ul></ul><ul><ul><li>‘ command followed by mark name </li></ul></ul><ul><ul><li>Return to mark </li></ul></ul>

33.
More Line-Editing Commands <ul><li>:h </li></ul><ul><ul><li>View vi help file </li></ul></ul><ul><li>Ctrl+] </li></ul><ul><ul><li>Navigate to hyperlinks in help files </li></ul></ul><ul><li>Ctrl+t </li></ul><ul><ul><li>Navigate back from links in help files </li></ul></ul>

36.
More Line-Editing Commands (continued) <ul><li>Shelling out </li></ul><ul><ul><li>Execute another Linux command </li></ul></ul><ul><ul><li>As if you were at shell prompt </li></ul></ul><ul><ul><li>Type ! followed by command </li></ul></ul><ul><ul><li>Example: :!ls /etc/samba </li></ul></ul>

37.
Setting vi Options <ul><li>:set all </li></ul><ul><ul><li>View all options currently set in vi </li></ul></ul><ul><ul><li>Press spacebar multiple times to see all screens of settings </li></ul></ul><ul><li>:set without the word all </li></ul><ul><ul><li>Displays all options that current user has set </li></ul></ul><ul><li>:set followed by option </li></ul><ul><ul><li>To set option </li></ul></ul>

40.
Summary <ul><li>Regular expressions used in many places to define patterns of information </li></ul><ul><li>grep command used to search for lines of text containing pattern defined using regular expression </li></ul><ul><li>sed and awk commands support complex scripting language that includes regular expressions </li></ul>