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

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
主站蜘蛛池模板: 老河口市| 白水县| 保德县| 古交市| 台东市| 仪陇县| 保德县| 宜阳县| 长子县| 宁远县| 景东| 广德县| 通江县| 如皋市| 寻甸| 龙江县| 邵东县| 峨眉山市| 台中市| 望奎县| 博罗县| 达州市| 东方市| 北流市| 顺昌县| 明光市| 汤原县| 衡南县| 鄢陵县| 永泰县| 南皮县| 旬阳县| 兴义市| 绥芬河市| 桦甸市| 灵武市| 曲阜市| 怀安县| 澄城县| 合肥市| 横山县|