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

Head and tail

For testing the next few commands, we will need a file with a sequence of numbers from 1 to 100. For this, use the following command:

    $ seq 100 > numbers.txt

The preceding command creates a file with the numbers 1 to 100 on separate lines. The following example shows the usage of the head command:

    $ head numbers.txt      // will display 10 lines
    $ head -3 numbers.txt   // will show first 3 lines
    $ head +5 numbers.txt   // will show from line 5. In few shells this command may not work

The following example shows the usage of the tail command:

    $ tail numbers.txt      // will display last 10 lines
    $ tail -5  numbers.txt        // will show last 5 lines
    $ tail +15 numbers.txt  // will show from line 15 onwards. In few shells this may not work

To print lines 61 to 65 from numbers.txt into file log.txt, type the following:

    $ head -65 numbers.txt | tail -5 > log.txt
主站蜘蛛池模板: 青岛市| 巴彦淖尔市| 井冈山市| 铜梁县| 磐石市| 东乌珠穆沁旗| 理塘县| 繁昌县| 澎湖县| 崇仁县| 陇川县| 萍乡市| 西平县| 泰来县| 沙洋县| 孟村| 青铜峡市| 通化县| 兰西县| 鱼台县| 徐闻县| 建昌县| 屯门区| 秦皇岛市| 顺义区| 福州市| 无为县| 临邑县| 齐河县| 扶沟县| 福建省| 金湖县| 乌兰察布市| 海原县| 淮阳县| 星座| 武义县| 盈江县| 五华县| 松桃| 镇远县|