在文件處理中,除了過濾和排序文件內容的統計信息外,它還經常用於合併多個文件、排序和合並多個文件或查找不重複的內容。
要解決上述問題,需要結合使用linux命令:cat命令、tail命令、sort命令、uniq命令、管道和重定向等。
讓我們看看一些具體使用示例吧~
- Linux下如何將多個文件合併成一個文件
使用tail命令和重定向符號“>”:顯示多個文件內容和相應的文件名
<code>➜ tail -n +1 file-* > file.log
#OR
➜ tail -n +1 file-1.log file-2.log file-3.log > file.log/<code>
-n, –lines=[+]NUM
輸出最後的NUM行;或者使用-n 參數,+NUM從第NUM行開始輸出
使用cat命令和重定向符號“>”:將多個文件合併到一個文件中
<code>➜ cat file-1.log file-2.log file-3.log > file.log
#OR
➜ cat file-* > file.log/<code>
<code>#重定向符號 ">": 覆蓋寫
#重定向符號 ">>": 追加寫/<code>
- 如何在linux/unix中對多個文件進行排序並排除重複數據後並導入一個文件
<code>➜ cat file-* | sort | uniq > file.log
/<code>
- 如何在linux/unix下對多個文件進行排序並將重複內容導出到一個文件
<code>➜ cat file-* | sort | uniq -d > file.log
/<code>
閱讀更多 閃電小白獸 的文章