8 Linux grep

Source: Internet
Author: User

    • Well, here can not complain because of network reasons, several times to write blog is the speed of the good coax to back, Dan Hurt Ah!

      • Text Search tool: Grep,egrep,fgrep

1 (1) grep "^[[:alpha:]]*"/proc/meminfo

(2)

grep "^[a-za-z]\+"/proc/meminfo

2 Grep-v ". *\/sbin\/nologin. *"/etc/passwd | Cut-d:-f1

Grep-v ". *\/sbin\/nologin$"/etc/passwd | Cut-d:-f1

3 grep ". *\/bin\/bash. *"/etc/passwd | Cut-d:-f1

grep ". *\/bin\/bash$"/etc/passwd | Cut-d:-f1

4 grep "\<[[:d igit:]][[:d igit:]]\>"/etc/passwd--color=auto

grep "\<[[:d igit:]]\{2\}\>"/etc/passwd--color=auto

5

grep "^[[:space:]]\{1,\}.*"/boot/grub/grub.conf grep "^[[:space:]]\+"

6 Displays the default shell for root, fedora, or User1 users on the current system

Egrep--color "^root|^fedora|^user1"/etc/passwd | cut-d:-f1,7 egrep--color "^ (root|fedora|user1) \>"/etc/passwd | Cut-d:-f1,7


7 Find the line after a word in the/etc/rc.d/init.d/functions file followed by a set of parentheses, such as: Hello ()

Egrep--color=auto "*\<[[:alnum:]]+\>\ (\)"/etc/rc.d/init.d/functions |cut-d "-f1

- o option

8 echo "/etc/sysconfig" | Grep

# basename/etc/sysconfig/

Sysconfig

echo "Etc/sysconfit/net-scripts" | Egrep--color=auto "*[^/]+$"

# Basename/etc/sysconfig

Sysconfig

Extension: Take out its path name

9 find the number between 1-255 in the ifconfig command result

Ifconfig | Egrep "\< ([0-9]|[ 1-9][0-9]|1[0-9][0-9]|2[0-5][0-5]) \> "--color=auto

10 Challenge: Write a pattern to match a reasonable IP address

11 Challenge: Write a pattern to match all email addresses

Because the specific e-mail address rules are unknown, so the following is written by themselves, feel good

Egrep--color=auto "^[[:alnum:]]+ (_?[ [: Alnum:]] +) {0,}@ ([[: Alnum:]]+\.) {0,} [[: alnum:]]+$] Matchmail.regexp




This article is from the "Ops Dog" blog, make sure to keep this source http://yunweigou.blog.51cto.com/6299641/1632012

8 Linux grep

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.