Linux-grep command

Source: Internet
Author: User
Tags svn

Example 1: find the specified process command: Ps-ef|grep SVN output:[[email protected] ~]# Ps-ef|grep Svnroot4943 1 0 Dec05? 00:00:00svnserve-d-r/opt/svndata/grape/root16867 16838 0 19:53 pts/0 00:00:00grep svn[[email protected] ~]#说明: The first record is the process of finding out; the second result is the grep process itself, not the process you are really looking for.
Example 2: find the specified number of processes command: Ps-ef|grep svn-cps-ef|grep-c svn output:[[email protected] ~]# Ps-ef|grep Svn-c2[[email protected] ~]# ps-ef|grep-c SVN2[[email protected] ~]#实例3: read keywords from file search command: Cat test.txt | grep-f test2.txt output:[[email protected] test]# cat Test.txt hnlinuxpeida.cnblogs.comubuntuubuntu linuxredhatredhatlinuxmint[[email protected] test]# cat Test2.txt linuxredhat[[email protected] test]# cat Test.txt | grep-f test2.txthnlinuxubuntu linuxredhatlinuxmint[[email protected] test]#说明: The output test.txt file contains the content lines of the keywords read out from the Test2.txt file
Example 4: read keywords from a file search and display line numbers command: Cat Test.txt | GREP-NF test2.txt Output:[[email protected] test]# cat Test.txt hnlinuxpeida.cnblogs.comubuntuubuntu linuxredhatredhatlinuxmint[[email protected] test]# cat Test2.txt linuxredhat[[email protected] test]# cat Test.txt | grep-nf test2.txt1: Hnlinux4: Ubuntu Linux6: Redhat7: LinuxMint[[email protected] test]#说明: The output test.txt file contains the content lines of the keywords read from the test2.txt file, and displays the line numbers of each row
Example 5: find keywords from file command: grep ' Linux ' test.txt output:[[email protected] test]# grep ' Linux ' test.txt hnlinuxubuntu linuxlinuxmint[[email protected] test]# grep-n ' Linux ' Test.txt1: Hnlinux4: Ubuntu Linux7: LinuxMint[[email protected] test]#实例6: find keyword commands from multiple files : grep ' linux ' test.txt test2.txt output:[[email protected] test]# grep-n ' Linux ' test.txt test2.txt test.txt:1: hnlinuxtest.txt:4: Ubuntu linuxtest.txt:7: linuxminttest2.txt:1: Linux[[email protected] test]# grep ' Linux ' test.txt test2.txt test.txt:hnlinuxtest.txt:ubuntu linuxtest.txt:linuxminttest2.txt:linux[[email protected] test]#说明: When multiple files are output, the name of the file is printed at the front of the row and added":"as a marker
Example 7:grep does not show itself the process command: PS aux|grep \[s]shps aux | grep ssh | grep-v"Grep"Output:[[email protected] test]# PS Aux|grep sshroot2720 0.0 0.0 62656 1212? Ss Nov02 0:00/usr/sbin/sshdroot16834 0.0 0.0 88088 3288? Ss 19:53 0:00 sshd: [Email protected]/0Root16901 0.0 0.0 61180 764 pts/0 s+ 20:31 0:00grep ssh[[email protected] test]# PS Aux|grep \[s]SH][[email protected] test]# PS Aux|grep \[s]Shroot2720 0.0 0.0 62656 1212? Ss Nov02 0:00/usr/sbin/sshdroot16834 0.0 0.0 88088 3288? Ss 19:53 0:00 sshd: [Email protected]/0[[email protected] test]# PS aux | grep SSH | Grep-v "grep"Root2720 0.0 0.0 62656 1212? Ss Nov02 0:00/usr/sbin/sshdroot16834 0.0 0.0 88088 3288? Ss 19:53 0:00 sshd: [Email protected]/0Example 8: find the line content that has the U start command: Cat test.txt |grep ^u output:[[email protected] test]# cat Test.txt |grep ^uubuntuubuntu linux[[email protected] test]#
Example 9: output A line content that does not start with a U command: Cat test.txt |grep ^[^u]Output:[[email protected] test]# cat Test.txt |grep ^[^u]Hnlinuxpeida.cnblogs.comredhatRedhatlinuxmint[[email protected] test]#实例10: Output the line content command ending in hat : Cat test.txt |grep hat$ output:[[email protected] test]# cat Test.txt |grep hat$redhatredhat[[email protected] test]#实例11: Command: Output:[[email protected] test]# ifconfig Eth0|grep "[0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\}\. [0-9]\{1,3\} "inet Addr:192.168.120.204 bcast:192.168.120.255 mask:255.255.255.0[[email protected] test]# ifconfig Eth0|grep-e "([0-9]{1,3}\.) {3} [0-9] "inet Addr:192.168.120.204 bcast:192.168.120.255 mask:255.255.255.0[[email protected] test]#实例12: displays a content line command containing an Ed or at character : Cat Test.txt |grep-e"Ed|at"Output:[[email protected] test]# cat Test.txt |grep-e "peida|com"peida.cnblogs.com[[email protected] test]# cat Test.txt |grep-e "Ed|at"Redhatredhat[[email protected] test]#实例13: Displays the line command for all strings that contain at least 7 consecutive lowercase characters for each string under the current directory in a file that ends in. txt : grep '[A- z]\{7\} ' *.txt output:[[email protected] test]# grep '[A- z]\{7\} ' *.txttest.txt:hnlinuxtest.txt:peida.cnblogs.comtest.txt:linuxmint[[email protected] test]#

Linux-grep command

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.