Filter the IP address of text filter accurately
Before writing himself to tidy up a bit of their usual always confused things, the most basic will not write, the front of the things do not want to see one eye, on the way to do IP filtering by the use of the side, see how to lock the IP address in the back.
First, regular expression (Patrern) brackets () square brackets [] angle brackets <> curly braces {} the use
\ [\] matches any single character in the specified range
[^] to match any single character other than the specified object
^[] any single character used to match the specified object and at the beginning of the line
\ (\) used as a back reference, or as a qualified or (\|) scope
\1 references the first opening parenthesis and all the contents of the closing parenthesis that correspond to it
\2
\3
\< Any character following it must appear as the header of the word
\> Any character in front of it must appear as the tail of the word
\<root\> Word root must be a separate word
\{\} used for matching times
\{m,n\} matches its first character at least m times, up to N times
Example: number begins with a number ending
grep ' \ ([0-9]\). *\1$ '/etc/inittab
To match any single character of a class [[:d igit:]],[[:lower:]],[[:upper:]],[[:p unct:]],[[:space:]],[[:alpha:]],[[:alnum:]]
Second, grep (Global Search), sort (text statistics),Cut (text Cut tool),WC (text statistics), TR (character processing command), Uniq (display repeating line, adjacent + same = repeat)
grep [option] pattern [file] [file1] ...
Common-i-v-O--color-e
-A # Displays the following # lines
- B # its front
- C # its front and back
Example:CPU Family and the following two lines
Grep-a 2 ' CPU family '/proc/cpuinfo
sort [option] [file]
-N Numeric sorting
-R descending order
-T Field delimiter
-K Sort whichever field
-F ignores character-case ordering
Cases:
SORT-T:-n-k3/etc/passwd
Cut [option] [File]
-D defining separators
-F is used with-D to specify the display of that area
-B split in bytes
-C is split in characters
Example: just look at the changes.
Netstat-nut | grep estab | awk ' {print $} ' Netstat-nut | grep estab | awk ' {print $} ' | Cut-d:-f1
WC [ option] [file]
-l display number of rows
-W Display number of words
-C Display of bytes
TR [option]
-D Delete all characters that appear in the character set
Cases:
cat/etc/passwd | Tr-d ' a '
Uniq [option] [File]
-C Displays the number of rows in a file
-D displays only duplicate rows
Third, ( play) filter the normal IP address and the IP address of the selected type
Sample:iptest.txt
127.0.0.1s ASDFDF
123.0.7.193
Wo 23.2.2.3
NETWORK127.0.0.1/16 is a bad guy
193.192.168.32
172.168.100.1
Normal IP: not recommended, but slightly faster
grep ' [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9] Iptest.txt
Class A IP: (B,c Class)
grep--color ' \<\ ([1-9]\|[ 1-9][0-9]\|1[01][0-9]\|12[0-7]\) \.\ ([0-9]\|[ 1-9][0-9]\|1[0-9][0-9]\|2[0-4][0-9]\|25[0-4]\) \.\ ([0-9]\|[ 1-9][0-9]\|1[0-9][0-9]\|2[0-4][0-9]\|25[0-4]\) \.\ ([0-9]\|[ 1-9][0-9]\|1[0-9][0-9]\|2[0-4][0-9]\|25[0-4]\) ' Iptest.txt
650) this.width=650; "src=" Http://s3.51cto.com/wyfs02/M00/70/BD/wKiom1W8Z3XCnpV0AAQoB4_LWcY999.jpg "title=" Qq20150801142723.png "alt=" Wkiom1w8z3xcnpv0aaqob4_lwcy999.jpg "/>
There is no shortage, the error will be sent to you by email: [Email protected]
This article is from "I just want to run quietly" blog, please be sure to keep this source http://gumpping.blog.51cto.com/9811308/1680822
Text filtering--grep,sort,wc,uniq,tr, precise filter IP address, Class A address, Class B address .... and sort