liunx 分割合并文件
一
dd的作用是轉換和拷貝文件,我們可以利用它來分割文件,相關的選項如下:
if=filename:輸入的文件名
of=finename:輸出的文件名
bs=bytes:一次讀寫的字節數,默認是512bytes
skip=blocks:拷貝前,跳過的輸入文件的前blocks塊,塊的大小有bs決定
count=blocks:只拷貝輸入文件的前blocks塊?
例如,現在有一個文件file,大小為116616字節:
[root]#?du?-b?file??
116616??file??
將其分割為兩文件file1和file2,那我們就設置每塊為1024字節,將file的前60塊放入file1,余下的放入file2:
[root]#?dd?if=file?bs=1024?count=60?skip=0??of=file1??
[root]#?dd?if=file?bs=1024?count=60?skip=60?of=file2??
然后用cat將兩個文件合并為file.bak,要注意文件的順序:
[root]#?cat?file1?file2?>?file.bak??
可以用md5sum驗證一下file和file.bak:
[root]#?md5sum?file??
3ff53f7c30421ace632eefff36148a70??file??
[root]#?md5sum?file.bak??
3ff53f7c30421ace632eefff36148a70??file.bak??
可以證明兩個文件時完全相同的。
二
grep手冊中的解釋:
Context Line Control
-A NUM, --after-context=NUM
? ?Print NUM ?lines ?of ?trailing ?context ?after ?matching ?lines.
? ?Places ? a ?line ?containing ?a ?group ?separator ?(--) ?between
? ?contiguous groups of matches. ?With the ?-o ?or ?--only-matching
? ?option, this has no effect and a warning is given.
-B NUM, --before-context=NUM
? ?Print ?NUM ?lines ?of ?leading ?context ?before ?matching lines.
? ?Places ?a ?line ?containing ?a ?group ?separator ?(--) ? between
? ?contiguous ?groups ?of ?matches. ?With the -o or --only-matching
? ?option, this has no effect and a warning is given.
-C NUM, -NUM, --context=NUM
? ?Print NUM lines of output context. ?Places a line ?containing ?a
? ?group separator (--) between contiguous groups of matches. ?With
? ?the -o or --only-matching option, ?this ?has ?no ?effect ?and ?a
? ?warning is given.
簡單翻譯就是,-A -B -C 后面都跟阿拉伯數字,-A是顯示匹配后和它后面的n行。-B是顯示匹配行和它前面的n行。-C是匹配行和它前后各n行。總體來說,-C覆蓋面最大。用它保險些。哈哈。這3個開關都是關于匹配行的上下文的(context)。
于是,
??grep?-A?4?wikipedia?密碼文件.txtgrep -A 100000 "/pic/" t_pic_queue
轉載于:https://blog.51cto.com/jueshizhanhun/1740683
《新程序員》:云原生和全面數字化實踐50位技術專家共同創作,文字、視頻、音頻交互閱讀總結
以上是生活随笔為你收集整理的liunx 分割合并文件的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: (NO.00005)iOS实现炸弹人游戏
- 下一篇: 智能机器人服务广州春运