tail命令與head命令用法類似,tail命令用於查看文檔的尾端指定數量的字符塊,默認顯示文檔的最後 10 行,python
若是給定的文件不止一個,則在顯示的每一個文件前面加一個文件名標題。express
tail命令的幫助文檔ubuntu
DESCRIPTION
Print the last 10 lines of each FILE to standard output. With more than one FILE, precede each
with a header giving the file name.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-c, --bytes=[+]NUM
output the last NUM bytes; or use -c +NUM to output starting with byte NUM of each file
-f, --follow[={name|descriptor}]
output appended data as the file grows;
an absent option argument means 'descriptor'
-F same as --follow=name --retry
-n, --lines=[+]NUM
output the last NUM lines, instead of the last 10; or use -n +NUM to output starting with line NUM
--max-unchanged-stats=N
with --follow=name, reopen a FILE which has not
changed size after N (default 5) iterations to see if it has been unlinked or renamed (this
is the usual case of rotated log files); with inotify, this option is rarely useful
二、命令選項app
-c, --bytes=K k,顯示文檔結尾的前 k 字節,+k,不顯示文檔開始的前 k-1 字節 -f, --follow[={name|descriptor}] 動態監視文檔最新追加的內容 -n, --lines=K k,顯示文檔結尾的 k 行,+k,不顯示文檔開始的前 k-1 行 -q, --quiet, --silent 當有多個文件參數時,不輸出各個文件名 -s, --sleep-interval=N 與「-f」選項連用,指定監視文件變化時間隔的秒數 --help 顯示此幫助信息並退出 --version 顯示版本信息並退出
實例:post
ubuntu:~/test$ cat lines.txt 01 02 03 04 05 06 07 08 09 10 11 12 ubuntu:~/test$ tail -5 lines.txt 08 09 10 11 12 ubuntu:~/test$
ubuntu:~/test$ tail +10 lines.txt 10 11 12 ubuntu:~/test$
NR表示從awk開始執行後,按照記錄分隔符讀取的數據次數,默認的記錄分隔符爲換行符,所以默認的就是讀取的數據行數,NR能夠理解爲Number of Record的縮寫。ui
在awk處理多個輸入文件的時候,在處理完第一個文件後,NR並不會從1開始,而是繼續累加,所以就出現了FNR,每當處理一個新文件的時候,FNR就從1開始計數,FNR能夠理解爲File Number of Record。this
NF表示目前的記錄被分割的字段的數目,NF能夠理解爲Number of Field。spa
-b:僅顯示行中指定直接範圍的內容; -c:僅顯示行中指定範圍的字符; -d:指定字段的分隔符,默認的字段分隔符爲「TAB」; -f:顯示指定字段的內容; -n:與「-b」選項連用,不分割多字節字符; --complement:補足被選擇的字節、字符或字段; --out-delimiter=<字段分隔符>:指定輸出內容是的字段分割符; --help:顯示指令的幫助信息; --version:顯示指令的版本信息。
Linux sed 命令是利用腳原本處理文本文件。code
sed 可依照腳本的指令來處理、編輯文本文件。blog
Sed 主要用來自動編輯一個或多個文件、簡化對文件的反覆操做、編寫轉換程序等。
sed [-hnV][-e<script>][-f<script文件>][文本文件]
參數說明:
動做說明:
給定一個文本文件 file.txt
,請只打印這個文件中的第十行。
tail -n +10 file.txt | head -1 awk 'NR==10' file.txt sed -n 10p file.txt cat -n file.txt | grep -E "^[[:space:]]{4}10" | cut -f1 --complement