![]() I equivalent to -binary-files=without-match a, -text equivalent to -binary-files=text TYPE is 'binary', 'text', or 'without-match' ![]() binary-files=TYPE assume that binary files are TYPE q, -quiet, -silent suppress all normal output o, -only-matching show only the part of a line matching PATTERN label=LABEL use LABEL as the standard input file name prefix h, -no-filename suppress the file name prefix on output H, -with-filename print file name with output lines line-buffered flush output on every line n, -line-number print line number with output lines b, -byte-offset print the byte offset with output lines m, -max-count=NUM stop after NUM selected lines V, -version display version information and exit v, -invert-match select non-matching lines z, -null-data a data line ends in 0 byte, not newline x, -line-regexp force PATTERN to match only whole lines w, -word-regexp force PATTERN to match only whole words i, -ignore-case ignore case distinctions e, -regexp=PATTERN use PATTERN for matching P, -perl-regexp PATTERN is a Perl regular expression G, -basic-regexp PATTERN is a basic regular expression (default) F, -fixed-strings PATTERN is a set of newline-separated strings E, -extended-regexp PATTERN is an extended regular expression Įxample: grep -i 'hello world' menu.h main.c If you want to get more detailed usage info about the grep command, and you can pass the “ –help” option to the grep command to output a useage message, type: Let’s see the second field from the above outputs, and it indicates the line number of matching line within its input file (/etc/passwd, or /etc/group). etc/passwd:10:operator:x:11:0:operator:/root:/sbin/nologin Outputs: ~]# grep -n "root" /etc/passwd /etc/group If you want to add prefix in each line of output with the 1-based line number within its input file when using grep command, and you need to pass the -n or –line-number option to the grep command, type: $ grep -n "root" /etc/passwd /etc/group Outputs: ~]# grep -l "root" /etc/passwd /etc/group If you only want to dispaly file names when using grep command to searching mathcing lines from the given files or directories in your Linux system, and you need to pass the “ -l ” option to the grep command, type: $ grep -l "pattern" fileNames etc/passwd:operator:x:11:0:operator:/ root:/sbin/nologinįorm the above outputs, you should know that the first field is the file name that contains the mathcing line. Outputs: ~]# grep "root" /etc/passwd /etc/group /etc/passwd: root:x:0:0: root:/ root:/bin/bash The syntax of the grep command is as followss: grep PATTERN įor example, you want to find a pattern “ root” from two given files “ /etc/passwd” and “ /etc/group” with grep command, just type: $ grep "root" /etc/passwd /etc/group
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |