Grep and find

Source: Internet
Author: User
Tags perl regular expression

Use grep and find tools 1. grep tool grep looks for strings in files, or rows that can match regular expressions. 1. To use the grep tool for regular expressions, you must be familiar with regular expressions. Otherwise, you can study it quickly. 2. Search for the text column grep-E "^ A" file.txt 3 starting with a in the file. Find the line grep-w "word" file.txt 4 with a word in the file, search for rows with word words in the file, which are case-insensitive grep-W "word"-I file.txt 5, find the grep-R "A [B-E] C" row that matches the regular expression a [B-E] C in all files in the current folder ". /* command line options: Usage: grep [Option]... pattern [file]... search for Pattern in each file or standard input. example: grep-I 'Hello world' menu. h main. c Regexp selection and interpretation:-E, -- extended-Regexp pattern is an ext Ended regular expression-F, -- fixed-strings pattern is a set of newline-separated strings-G, -- Basic-Regexp pattern is a basic regular expression-P, -- Perl-Regexp pattern is a Perl regular expression-E, -- Regexp = pattern use pattern as a regular expression-F, -- file = file obtain pattern from file-I, -- ignore-case ignore case distinctions-W, -- word-Regexp force pattern to match only whole word S-X, -- line-Regexp force pattern to match only whole lines-Z, -- null-data a data line ends in 0 byte, not newline Miscellaneous:-s, -- no-messages suppress error messages-V, -- invert-match select non-Matching lines-V, -- version print version information and exit -- help display this help and exit -- MMAP use memory-mapped input if possible output control:-M, -- Max-Count = num stop after num match Es-B, -- byte-offset print the byte offset with output lines-N, -- line-Number Print line number with output lines -- line-buffered flush output on every line-H, -- With-filename print the filename for each match-h, -- no-filename suppress the prefixing filename on output -- Label = label print label as filename for standard input-o, -- only-matching show only the part of a line matching pattern-Q ,- -Quiet, -- silent suppress all normal output -- Binary-files = type assume that binary files are type is 'binary ', 'text', or 'without-Match'-, -- text equivalent to -- Binary-files = text-I equivalent to -- Binary-files = without-match-D, -- directories = action how to handle directories action is 'read ', 'recurse', or 'skip'-D, -- devices = action how to handle devices, operating OS and sockets action is 'rea D' or 'skip'-R,-R, -- Recursive equivalent to -- directories = recurse -- include = pattern files that match pattern will be examined -- exclude = pattern files that match pattern will be skipped. -- exclude-from = file files that match pattern in file will be skipped. -l, -- files-without-match only print file names containing no match-L, -- files-with-matches only print file names containing matches-C, -- C Ount only print a count of Matching lines per file-Z, -- null print 0 byte after file name context control:-B, -- before-context = num print num lines of leading context-a, -- After-context = num print num lines of trailing context-C, -- Context = num print num lines of output context-num same as -- Context = num -- color [= when], -- color [= when] use markers to distinguish the matching string when may be 'a Lways ', 'Never' or 'auto '. -u, -- binary do not strip Cr characters at EOL (msdos)-u, -- Unix-byte-offsets report offsets as if CRS were not there (msdos) 'egrep 'means 'grep-e '. 'fgrep' means 'grep-F '. with no file, or when file is-, read standard input. if less thantwo files given, assume-H. exit status is 0 if match, 1 if no match, and 2 if trouble. 2. Find tool find finds the file name in a directory. -name "s *" command line option Usage: Find [-H] [-L] [-p] [-olevel] [-D help | tree | search | stat | opt] [path...] [expression] default path is the current directory; default expression is-printexpression may consist of: operators, options, tests, and actions: operators (decreasing precedence; -And is implicit where no others are given): (expr )! Expr-not expr expr1-A expr2 expr1-And expr2 expr1-O expr2 expr1-or expr2 expr1, expr2 positional options (always true ): -daystart-Follow-regextype normal options (always true, specified before other expressions ): -Depth -- Help-maxdepth levels-mindepth levels-mount-noleaf -- version-xdev-ignore_readdir_race-noignore_readdir_race tests (N can be + N or-N or N ): -Amin N-anewer file-atime N-Cmin N-cnewer file-ctime N-empty-False-fstype type-gid N-group name-ilname pattern-INAME pattern-inum n -iwholename pattern-iregex pattern-links N-lname pattern-mmin N-mtime N-name pattern-newer file-nouser-nogroup-path pattern-Perm [+-] mode-RegEx pattern-readable-writable-executable-wholename pattern-size N [bcwkmg]-True-type [bcdpflsd]-uid n-used n-user name-xtype [bcdpfls] actions: -Delete-print0-printf format-fprintf file format-print-fprint0 file-fprint file-ls-FLS file-prune-Quit-exec command; -exec command {}+-OK command;-execdir command {}+-okdir command;

 

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.