我知道我可以使用cat
在Linux上從頭到尾打印文件中的所有內容。 有沒有辦法做到這一點(最後一行)?如何在Linux上向後讀取文件?
3
A
回答
6
sed '1!G;h;$!d' file
sed -n '1!G;h;$p' file
perl -e 'print reverse <>' file
awk '{a[i++]=$0} END {for (j=i-1; j>=0;) print a[j--] }' file
9
是的,你可以使用「tac」命令。
從人TAC:
Usage: tac [OPTION]... [FILE]...
Write each FILE to standard output, last line first.
With no FILE, or when FILE is -, read standard input.
Mandatory arguments to long options are mandatory for short options too.
-b, --before attach the separator before instead of after
-r, --regex interpret the separator as a regular expression
-s, --separator=STRING use STRING as the separator instead of newline
--help display this help and exit
--version output version information and exit
4
tac
是一種方式,但不是默認適用於所有的Linux操作系統。
awk中能做到這一點,如:
awk '{a[NR]=$0}END{for(i=NR;i>=1;i--)print a[i]}' file
相關問題
- 1. 如何在向後讀取文件後關閉文件?
- 2. 如何向後讀取文件?
- 3. 如何在Linux中讀取INI文件
- 4. Groovy向後讀取文件
- 5. SAS - 向後讀取文件?
- 6. 在Mathematica中向後讀文件 - 如何?
- 7. 調用lseek64後從文件讀取 - Linux
- 8. 如何確保您的文件將在Linux/Windows上讀取
- 9. 如何找到在Linux上讀取文件夾
- 10. linux-kernel如何讀取proc/pid文件?
- 11. 讓PHP讀取Linux上的.doc文件
- 12. 向後讀文件?
- 13. 向後讀取二進制文件
- 14. 逐行向後讀取文件行
- 15. 在linux中爲事件文件讀取()
- 16. Linux讀取文件權限
- 17. 讀取文件,獲取當前位置並向後讀取
- 18. Linux bash從文件讀取然後adduser到linux
- 19. 如何在上傳到服務器後讀取文件
- 20. 在Linux C++上讀取CPU
- 21. 如何在Linux上的rstudio中讀取中文
- 22. 無法在linux中讀取文件
- 23. 在Linux中同步讀取文件C
- 24. 如何讀取Linux中的文件/文件夾屬性?
- 25. 用Python在Linux上高效地讀取csv文件在Python中
- 26. 如何在Linux中讀取.xls與cpp文件
- 27. 如何在linux中創建無法讀取的文件
- 28. 如何在Linux平臺中讀取SQL Server CE SDF文件
- 29. 如何在linux環境下讀取windows文件
- 30. 如何在Linux內核模塊中讀取/寫入文件?
你是什麼意思的 「讀」 嗎?具體說明文件的內容以及您期望的「倒退」結果。 – 2013-02-18 10:44:41
我想看看2GB文件的結尾,所有2GB在一行上,所以我做了這個「dd if = file.xml ibs = 1 skip = 2049186000 count = 100」 - 意思是從位置2049186000開始讀取100個字節。輸出有一些dd的東西,但它的工作。 – bobef 2014-05-23 02:47:15