- 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
推薦閱讀
- Unreal Engine:Game Development from A to Z
- 32位嵌入式系統與SoC設計導論
- AutoCAD快速入門與工程制圖
- 軟件架構設計
- R Machine Learning By Example
- 數據中心建設與管理指南
- STM32G4入門與電機控制實戰:基于X-CUBE-MCSDK的無刷直流電機與永磁同步電機控制實現
- 計算機網絡技術實訓
- 現代機械運動控制技術
- AWS Certified SysOps Administrator:Associate Guide
- CompTIA Linux+ Certification Guide
- Hadoop Beginner's Guide
- 計算機組裝與維修實訓
- Flash CS5二維動畫設計與制作
- ARM嵌入式開發實例