Linux Command grep, linux Command grep

Source: Internet
Author: User
Tags subdomain

Linux Command grep, linux Command grep

Grep command: print the line matching a style in the file

Format: grep [options] pattern [filles]

Options):

Options for style control:

-E: Extended grep, egrep

-F regex-file: Get the regular expression from the file, fgrep

-I: case insensitive

#cat argvs.sh #!/bin/bashecho $0 with $# args: "$*"index=1for arg in $*doecho Argument ${index} is: ${arg}let "index+=1"doneexit grep -i FOR argvs.sh for arg in $*

-V: only obtain results that do not match

 grep -v -i For argvs.sh #!/bin/bashecho $0 with $# args: "$*"index=1doecho Argument ${index} is: ${arg}let "index+=1"doneexit

Control output options:

-C: only the number of matched lines in the output file

# grep -c -i For argvs.sh 1

-L: only the file names matching the content are output.

grep -l do *.sh argvs.shps3_test.sh

-L: opposite to-l, the output content does not match the file name.

# grep -L for *.sh ps3_test.sh

-M num: Find num matching rows and stop searching.

grep -m 10 '\/etc' all.txt /etc/etc/securetty/etc/python2.6/etc/python2.6/sitecustomize.py/etc/bash.bashrc/etc/apparmor/etc/apparmor/severity.db/etc/apparmor/subdomain.conf/etc/apparmor/functions/etc/apparmor/logprof.conf

Options for the first grid of the output row:

-N: displays the row number of the output row in the file.

-H: No output file name

-H: output file name

 grep -H -n -m 10 '\/etc' all.txt all.txt:1:/etcall.txt:2:/etc/securettyall.txt:3:/etc/python2.6all.txt:4:/etc/python2.6/sitecustomize.pyall.txt:5:/etc/bash.bashrcall.txt:6:/etc/apparmorall.txt:7:/etc/apparmor/severity.dball.txt:8:/etc/apparmor/subdomain.confall.txt:9:/etc/apparmor/functionsall.txt:10:/etc/apparmor/logprof.conf

Pattern: Regular Expression

Files (File Name): the file name is not specified and is read from the standard input by default.

#grep -m 10 -n '^\/etc.*conf$' all.txt 8:/etc/apparmor/subdomain.conf10:/etc/apparmor/logprof.conf14:/etc/laptop-mode/conf.d/auto-hibernate.conf15:/etc/laptop-mode/conf.d/sched-mc-power-savings.conf16:/etc/laptop-mode/conf.d/cpufreq.conf17:/etc/laptop-mode/conf.d/start-stop-programs.conf18:/etc/laptop-mode/conf.d/hal-polling.conf19:/etc/laptop-mode/conf.d/configuration-file-control.conf20:/etc/laptop-mode/conf.d/dpms-standby.conf21:/etc/laptop-mode/conf.d/usb-autosuspend.conf
# grep -m 10 -n '^\/etc.*conf$' /etc .conf1:/etc .confee/et aa/etcdasdaweq/conf4:/etcdasdaweq/conf


Zookeeper

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.