官术网_书友最值得收藏!

Pattern searching using grep

The command g/RE/p stands for globally search for the regular expression (RE) and print the line. The return statuses are 0 for success, 1 for pattern not found, and 2 for file not found:

    $ ps -ef | grep root

The preceding command will show all processes running currently whose user ID is root.

    $ ll /proc | grep "cpuinfo"

The preceding command will show the file with the name cpuinfo from the /proc directory.

    $ grep -lir "text" *          // show only file names containing text //   
    $ grep -ir "text" dir_name    // show lines of files //

We will try the following commands on file love.txt:

We will create a new file sample.txt, as follows:

Apple Fruit 5  4.5

Potato Vegetable 4  .5

Onion Vegetable .3  8

Guava Fruit 5  1.5

Almonds Nuts 1 16

Tomato Vegetable 3  6

Cashew Nuts 2  12

Mango Fruit 6  6

Watermelon Fruit 5  1

We will try the following commands on the sample.txt file:

主站蜘蛛池模板: 邹平县| 会泽县| 蚌埠市| 沂水县| 睢宁县| 珠海市| 噶尔县| 灵石县| 宝山区| 永新县| 内丘县| 灌南县| 宜州市| 乐昌市| 瑞丽市| 玛沁县| 疏勒县| 敖汉旗| 金华市| 那坡县| 华亭县| 南召县| 通许县| 通许县| 乐清市| 望城县| 望城县| 沅陵县| 沾益县| 浮梁县| 额尔古纳市| 高陵县| 榆林市| 阳江市| 沂南县| 夏河县| 靖边县| 安阳县| 于田县| 建宁县| 盈江县|