Introduction to grep commands in AIX

Source: Internet
Author: User
Tags egrep

Introduction to grep commands in AIX [plain] www.2cto.com grep three types of deformation 1. grep: Standard command, search for text, you can use a regular expression. 2. egrep: Extended grep. It supports basic and extended regular expressions, but does not support applications in the \ p mode range. 3. fgrep: Quick grep, which allows searching strings instead of a mode. In the grep command, it is best to enclose string parameters in double quotation marks. Grep Command Option:-c: Only output matched rows-I: case-insensitive (only single character applies)-h: When querying multiple files, the file name-l is not displayed: when querying multiple files, only the file name containing matching characters is output-n: the matching row and row number are displayed-s: the error message that does not exist or no matching text is displayed-v: show all rows that do not contain matching files to query multiple files: grep "sort "*. doc in all files, query "sort it": grep "sort it" * to view data. f file content pg data. f 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sept 5AP1996 USP 65.00 LVX2C 189 47 Otc 3Z1998 LPSX 43.00 Jun 512 DEC 2CC1999 CAD 219 PLV2C 68 23.00 nov 7PA1998 CAD 484 PLV2C 49.00 234 m Ay 5PA1998 USP 37.00 KVM9D 644 216 sept 3ZL1998 USP 86.00 KVM9E 234 contains "48" rows: grep-c "48" data. f 4 contains all rows of "48": grep "48" data. f 48 Dec 3BC1997 LPSX 68.00 LVX2A 138 483 Sept 5AP1996 USP 65.00 LVX2C 189 484 nov 7PA1998 CAD 49.00 PLV2C 234 483 may 5PA1998 USP 37.00 KVM9D 644 display the row number matching: grep-n "48" data. f Dec 3BC1997 LPSX 68.00 LVX2A 138 2: 483 Sept 5AP1996 USP 65.00 LVX2C 189 5: 484 nov 7PA1998 CAD 49.00 PLV2C 234 6: 483 may 5PA1998 USP 37.00 KVM9D 644 displays rows that do not contain "48": grep-v "48" data. f 47 Otc 3Z1998 LPSX 43.00 KVM9D 512 219 DEC 2CC1999 CAD 23.00 PLV2C 68 216 sept 3ZL1998 USP 86.00 KVM9E 234 ignore case sensitivity: grep-I "sept" data. f 483 Sept 5AP1996 USP 65.00 LVX2C 189 216 sept 3ZL1998 USP 86.00 KVM9E 234 grep and regular expression: 1. unmatched line header: grep '^ [^ 48] 'data. f 219 DEC 2CC1999 CAD 23.00 PLV2C 68 216 sept 3ZL1998 USP 8 6.00 KVM9E 234 2. mode range: grep '48 [34] 'data. f 483 Sept 5AP1996 USP 65.00 LVX2C 189 484 nov 7PA1998 CAD 49.00 PLV2C 234 483 may 5PA1998 USP 37.00 KVM9D 644 3. case Sensitive grep '[Ss] ept 'data. f 483 Sept 5AP1996 USP 65.00 LVX2C 189 216 sept 3ZL1998 USP 86.00 KVM9E 234 4. match any character K followed by three characters, and then D: grep 'K... D 'data. f 47 Otc 3Z1998 LPSX 43.00 KVM9D 512 483 may 5PA1998 USP 37.00 KVM9D 644 K followed by 2 characters, then 9: grep 'K. \ {2 \} 9 'data. f 47 Otc 3Z1998 LPSX 43.00 KVM9D 512 483 may 5PA1998 USP 37.00 KVM9D 644 216 sept 3ZL1998 USP 86.00 KVM9E the first two characters are uppercase letters, ending with C and two arbitrary characters in the middle: grep '[A-Z] [A-Z] .. C 'data. f 483 Sept 5AP1996 USP 65.00 LVX2C 189 219 DEC 2CC1999 CAD 23.00 PLV2C 68 484 nov 7PA1998 CAD 49.00 PLV2C 234 grep '5 .. 199 [6, 8] 'data. f 483 Sept 5AP1996 USP 65.00 LVX2C 189 483 may 5PA1998 USP 37.00 KVM9D 644 match any position in a row: grep '[0- 9] [0-5] [0-6] 'data. f 47 Otc 3Z1998 LPSX 43.00 KVM9D 512 484 nov 7PA1998 CAD 49.00 PLV2C 234 483 may 5PA1998 USP 37.00 KVM9D 644 sept 3ZL1998 USP 216 KVM9E 86.00 match the first position of a row: grep '^ [0-9] [0-5] [0-6] 'data. f 216 sept 3ZL1998 USP 86.00 KVM9E 234 appears at least n times: grep '4 \ {2, \} 'data. f 483 may 5PA1998 USP 37.00 KVM9D 644 5. use grep to match "with" or "or" Mode-E: Allow to use extended mode to match grep-E '100 | 100' data. f 219 DEC 2CC1999 CAD 23.00 PLV2C 68 216 sept 3ZL1998 USP 86.00 KVM9E 234 blank line: [development]/usr/xxxx/ytcclb> grep '^ $ 'info.txt [development]/usr/xxxx/ytcclb> matched IP Address: grep '[0-9] \ {3 \}\. [0-9] \ {3 \}\. [0-9] \ {3 \}'*. address class name and its equivalent Regular Expression ------------------------------- equivalent Regular Expression of the class [[: upper:] [A-Z] [[: lower:] [a-z] [: digit:] [0-9] [[: alnum:] [0-9a-zA-Z] [[: space:] space or tab key [[: alpha:] [a-zA-Z] ------------------------------ the system grep command is combined with the pipeline command. |, the output result on the left is used Enter the command on the right to find the list in the directory list: ls-l | grep '^ d' to query all files in the directory that do not contain the directory: ls-l | grep '^ [^ d]' [/home/xxxx/ytcxx]> ls-l | grep '^ d ..... x .. x 'drwxr-xr-x 4 xxxx db2iadm1 256 Nov 15 2010 cdxx drwxr-xr-x 2 xxxx db2iadm1 4096 Dec 6 2006 incl drwxr-xr-x 2 xxxx db2iadm1 256 Nov 25 2010 src drwxr-xr-x 2 xxxx db2iadm1 256 Nov 25 2010 tbin drwxr-xr-x 3 xxxx db2iadm1 4096 Jul 5 2011 test drwxr-xr-x 5 xxxx db2iadm1 256 Sep 10 20 10 tmp ps command to query the processes running on the shampoo. [/Home/xxxx/ytcclb]> ps ax | grep "named" 376944 pts/0 A grep named [/home/xxxx/ytcclb]> ps-ef | grep "named "xxxx 573474 557246 0 10:20:42 pts/0 grep named string use the grep command: STR = "Mary Joe Peter Paine" echo $ STR | grep "Mary" Mary Joe Peter Paine egrep: expression or extended grep, which accepts all regular expressions. Egrep '(3ZL | 2CC) 'Data. f 219 DEC 2CC1999 CAD 23.00 PLV2C 68 216 sept 3ZL1998 USP 86.00 KVM9E 234

Related Article

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.