The Three Musketeers of Linux text Processing

Source: Internet
Author: User

Grep: Text Filtering tool, (GREP,EGREP,FGREP) Sed: Text Editing Tool, Awk: Text Report Generator

grep: Function Text Search tool to step through the target file matching checks according to user-specified ' mode, print matching lines

grep root/etc/passwd grep command options:

grep "$USER"/etc/passwd-v shows lines that are not matched by pattern-e show only the matched string

grep "$USER '/etc/passwd-i ignores character case-C statistics match to the number of rows-W match word

grep ' WhoAmI '/etc/passwd-n displays the matching line number-A # After a few lines-b# the first few lines-c# before and after # lines

Nmap Scan Tool nmap-sp-v 172.18.252.0/24 |grep-b1 up |grep scan |cut-d "f5 > 1.txt scan up IP address

NMAP-V-A IP address scan the open port of the machine

Ifconfig eth1 |grep "inet addr" |cut-d:-f2|cut-d ""-F1 Filter IP Address

DF |grep/dev/sd|tr-s '%|cut-d%-f5|sort-nr|head-1 view disk maximum usage

Regular Expressions: Another class of special characters and text characters written by the mode, indicating that the function of control or wildcard divided into two categories: basic regular Expression BRE extended regular expression ERE

Character matching:. Match a single arbitrary character

[] matches any single character within the specified range

[^] matches any single character outside the specified range

Number of matches: * matches the preceding character any time, including 0 position anchoring: ^ Meow at the beginning of the line

. * Match any character any time $ line end Meow

\? Matches the preceding character 0 or 1 times ^$ represents a blank line ^pattern$ used for pattern matching positive rows

\+ matches the preceding character at least once ^[[:space:]]*$ a blank line

\{n\} matches the preceding character n times \< or \b The first meow \> or \b The suffix meow, for the right side of the word pattern

\{m,n\} matches the preceding character at least m times, up to N times \<pattern> matches the entire word

\{,n\} matches the preceding character up to n times

\{n,\} matches the preceding character at least n times

Group: \ (\) binds one or more characters together and treats them as a whole, such as: \ (root\) \+

1. Cat/proc/meminfo | grep ^[ss].*-o     or Cat/proc/meminfo | Grep-i ' ^s.* 2.grep-v "/bin/bash$"/etc/passwd3.cat/etc/passwd |grep "^RPC:" |cut-d:-f  74.grep "\b[0-9]\? [0-9] [0-9]\b "/etc/passwd   or   grep" \b[0-9]\{2,3\}\b "/etc/passwd 5.grep ' ^[[: space:]]\ + [^ [: space:] ] '  /etc/grub2.cfg6.netstat-tan |grep "listen[[:space:]]*$" 7.cut-d ":"-f1,3/etc/passwd |grep "\<[0-9]\{1,3\} \> "centos6:   cut-d": "-f1,3/etc/passwd |grep" \b[1-9]\? [0-9]\b "-E" \b[0-4][0-9]\{2\}\b "8.grep" ^\ (. *\) \>.*\<\1$ "/etc/passwd  or grep" ^\ (. *\):. *\<\1$ " / ETC/PASSWD9.DF |grep '/dev/sd ' |grep-o ' [0-9]\+% ' |tr-d%|sort-nr extended Regular Expression:   *: Matches the preceding character any time    &n bsp;                          ? : 0 or 1 times                                +  : 1 or more times                                 {m} : Matching M-Times                                  {m,n}: At least m, up to N times                                 a|b:  A or b                               c| Cat:c or cat                               (c|c) at:  cat or cat

The Three Musketeers of Linux text Processing

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.