1 grep (General Regular Expression Parse) Command Format: grep [option] pattern fileoption: n (-- line-number)-display row I (-- ignore-case) -case-insensitive E (-- regexp = PATTERN)-use an extended regular metadatchset or use egrepl (-- files-with-matches) -list matching file names v (-- invert-match)-reverse matching r (-- recursive) -recursive search for all files in the directory. 2 common Regular Expressions: Basic metacharacter set $ grep-n ^ public t1.txt $ grep-n public $ t1.txt $ grep-n ^ $ t1.txt $ grep-n \ <public t1.txt $ grep-n' \ <public 't1.txt $ grep-n' public \> 't1.txt $ grep-n "\ <public" t1.txt $ grep-n ^. $ t1.txt $ grep-n 11 [MNX] t1.txt $ grep-n 11 [^ MNX] t1.txt $ grep-n go * d t1.txt double quotation marks differ from single quotation marks, double quotation marks cannot suppress \ and $ characters $ grep-n' \ 't1.txt $ grep-n "\" t1.txt extended metacharacters $ grep-nE go + d t1.txt $ grep -nE 10 {3} A t1.txt $ grep-nE "10 {2, 4} A" t1.txt $ grep-nE 10 \ {2, 4 \} A t1.txt $ grep-nE '11a | B 't1.txt $ grep-nE net \ (works \) * use the example in t1.txt3 grep to query multiple files with wildcards $ grep-n test *. txt reverse match $ ps aux | grep sshd | grep-v grep recursive search $ grep-nr telnet/etc only list matching file names $ grep-l test *. in txt 4 vi, use a regular expression to delete all characters from aa to zz in the current row: s/aa. * zz // replace and in the entire file with &: 1, $ s/and/\ &/g, insert new: 1 at the beginning of each row, $ s/^/new/Insert @: 2 at the end of row 2nd to row 5th, 5S/$/@/g remove all the numeric characters at the beginning of the line: s/^ [0-9] + // g example: Switch Parameter foo (, 2) foo (, 2) foo (x + 13, y-2, 10) foo (y-2, x + 13, 10) foo (bar (8), x + y + z, 5) foo (x + y + z, bar (8), 5 ): 1, $ s/foo (\ ([^,] * \), \ ([^,] * \), \ ([^ \)] *) /foo (\ 2, \ 1, \ 3)/g