shell script - programming prelude - grep gadgets of

Goal :
to understand the shell wildcard
familiar with grep gadgets and use the shell wildcard

What is grep ?
grep is a line filter tool; a filter based on keywords
(1) syntax and options
Syntax:
# grep option 'keywords' file name
(2) Common Options:
Options:
-i: case-insensitive
-v: Locates including the designation for the line, reverse selection
-w: by word search
-o: print matched keywords
-c: count the number of matches to
-n: display the line number
-r: directory traversal layer by layer to find
-A: display matching lines After the line number and
-B: displaying the matched row and front row number
-C: Show how many matching rows and longitudinal rows
-l: lists only the file name matching
-L: lists the file name does not match
-e: match using regular
-E: use extended regular match
^ key: starts with the keyword
key $: ends with the keyword
^ $: matches the empty row
--color = auto: you can find the key portion plus color display
(3) color display (alias):
temporary settings:
# alias grep = 'grep --color = Auto' // only take effect for the current terminal and the current user
permanently set:
1) Global (effective for all users)
VI / etc / bashrc
Alias = grep '= Auto --color grep'
Source / etc / bashrc
2) topical (for a specific user)
VI ~ / .bashrc
Alias = grep ' Auto --color = grep '
Source ~ / .bashrc
(. 4) illustrates:
grep -i ignore the passwd root contains the root case of the match line
grep -w ftp passwd exact word match ftp
grep -w hello passwd he11o exact matching words; add their own line contains he1o to file
grep -wo ftp passwd print to match the keywords the FTP
grep -n root passwd root keyword print matching to the line of
grep -ni root passwd line match statistics ignore case containing the keyword root of
grep -nic root passwd match statistics ignore case containing the keyword root of the number of rows
grep -i ^ root passwd ignore case match starts with root line
grep bash $ passwd four in a row ending bash
grep -n ^ $ passwd matches an empty line and print the line numbers
grep ^ # /etc/vsftpd/vsftpd.conf match the number of lines that begin with #
grep -V ^ # / etc / vsftpd / vsftpd. conf no match lines beginning with a #
grep -A 5 mail passwd matching keywords and after 5 comprising mai1 line
grep -B 5 mail passwd comprising matching keywords and their mai1 first 5 rows
grep -C 5 mail passwd contains mai1 match keywords and their five lines before and after


the actual
1. specific needs: keywords section can see at a glance?

cat /etc/passwd | grep --color=auto 'root'

2. Specific needs: to simplify the above code, how to see?

3. Specific Requirements: How, can still be seen at the next logon?

Modify the configuration file

we /etc/bash.bashrc

Finally add
alias grep = 'grep --color = auto '

Re-read
source /etc/bash.bashrc

root users to view next

Switch to the next test1 users to view, still can be achieved in realizing the global

4. Specific requirements: Check how many rows

5. Specific needs: View a keyword, regardless of capitalization

5. Specific needs: Find begins with the keyword

6. specific needs: to exclude a keyword search

7. Specific requirements: keyword end

8. specific needs: to see the previous three lines of a keyword

9. specific needs: a keyword to see the 3 lines

10. specific needs: Contains content keyword incomplete, so to ask to see the top and bottom combination (see the front 33 rows and rows after a keyword)

11. specific needs: Find a word according to

12. specific needs: just look for the keyword itself

Guess you like

Origin www.cnblogs.com/-lyr/p/12152565.html