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

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
主站蜘蛛池模板: 稷山县| 香河县| 贞丰县| 封丘县| 元阳县| 米泉市| 孟村| 昂仁县| 旬阳县| 宁德市| 婺源县| 邹平县| 静乐县| 陵水| 米泉市| 田林县| 定南县| 临夏县| 萝北县| 华阴市| 永嘉县| 洛浦县| 灵璧县| 疏附县| 新兴县| 穆棱市| 祁东县| 镇宁| 满洲里市| 霍城县| 阳曲县| 澄城县| 东乌珠穆沁旗| 平和县| 福鼎市| 肇源县| 肇源县| 陵川县| 禹城市| 浦江县| 从化市|