- Learning Linux Shell Scripting
- Ganesh Naik
- 165字
- 2021-06-25 22:02:49
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
推薦閱讀
- 自動(dòng)控制工程設(shè)計(jì)入門(mén)
- ABB工業(yè)機(jī)器人編程全集
- Go Machine Learning Projects
- 大數(shù)據(jù)挑戰(zhàn)與NoSQL數(shù)據(jù)庫(kù)技術(shù)
- 現(xiàn)代機(jī)械運(yùn)動(dòng)控制技術(shù)
- 數(shù)據(jù)庫(kù)原理與應(yīng)用技術(shù)
- Visual Basic.NET程序設(shè)計(jì)
- Visual FoxPro數(shù)據(jù)庫(kù)基礎(chǔ)及應(yīng)用
- 軟件工程及實(shí)踐
- 未來(lái)學(xué)徒:讀懂人工智能飛馳時(shí)代
- 計(jì)算機(jī)應(yīng)用基礎(chǔ)實(shí)訓(xùn)(職業(yè)模塊)
- 工業(yè)機(jī)器人技術(shù)
- 運(yùn)動(dòng)控制系統(tǒng)應(yīng)用及實(shí)例解析
- 單片機(jī)C語(yǔ)言編程實(shí)踐
- 仿蛛機(jī)器人的設(shè)計(jì)與制作