成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Linux如何對文件進行分割和重組

系統 Linux
csplit 中的 “c” 是上下文(context)的意思。也就是說可以根據任意匹配的方式或者巧妙的正則表達式來分割文件。

csplit,split 和 cat 來重新整理文件,然后再將文件合并在一起。這些操作在任何文件類型下都有用:文本、圖片、音頻文件、ISO 鏡像文件等。

使用 csplit 分割文件

csplit 將單個文件分割成多個文件。

[root@k8s-master-node1 test]# cat 1
1
2
3
4
5
6
[root@k8s-master-node1 test]#

它將文件 1 分為三個文件,以行號 2 和 5 作為分割點

[root@k8s-master-node1 test]# csplit 1 2 5
2
6
5
[root@k8s-master-node1 test]#

csplit 在當前目錄下創建了三個新文件,并以字節為單位打印出新文件的大小。默認情況下,每個新文件名為 xx_nn:

[root@k8s-master-node1 test]# ls
1 xx00 xx01 xx02
[root@k8s-master-node1 test]#

分別查看內容

[root@k8s-master-node1 test]# cat xx00
1
[root@k8s-master-node1 test]# cat xx01
2
3
4
[root@k8s-master-node1 test]# cat xx02
5
6

[root@k8s-master-node1 test]#

如果要將文件分割成包含相同行數的多個文件如何操作呢?

可以指定行數,然后將重復次數放在在花括號中。此示例重復分割 4 次,并將剩下的轉儲到最后一個文件中

[root@k8s-master-node1 test]# csplit 1 1 {4}
0
2
2
2
2
5

可以使用星號通配符來告訴 csplit 盡可能多地重復分割。這聽起來很酷,但是如果文件不能等分,則會失敗(低版本的 csplit 不支持此參數)

[root@k8s-master-node1 test]# csplit 1 1 {*}
0
2
2
2
2
2
2
1
csplit: ‘1’: line number out of range on repetition 7
[root@k8s-master-node1 test]# cat 1 |wc -l
7
[root@k8s-master-node1 test]#

默認的行為是刪除發生錯誤時的輸出文件。

可以用 -k 選項來解決這個問題,當有錯誤時,它就不會刪除輸出文件。

另一個行為是每次運行 csplit 時,它將覆蓋之前創建的文件,如果需要使用新的文件名來分別保存它們。可以使用使用 --prefix= prefix 來設置一個不同的文件前綴:

[root@k8s-master-node1 test]# csplit -k --prefix=mine 1 1 {*}
0
2
2
2
2
2
2
1
csplit: ‘1’: line number out of range on repetition 7
[root@k8s-master-node1 test]# ls
1 mine00 mine01 mine02 mine03 mine04 mine05 mine06 mine07
[root@k8s-master-node1 test]#

-n 可用于改變對文件進行編號的數字位數(默認是 2 位):

[root@k8s-master-node1 test]# ls
1 mine0 mine1 mine2 mine3 mine4 mine5 mine6 mine7
[root@k8s-master-node1 test]#

csplit 中的 “c” 是上下文(context)的意思。也就是說可以根據任意匹配的方式或者巧妙的正則表達式來分割文件。

下面的例子將文件分為兩部分。第一個文件在包含第一次出現 “3” 的前一行處結束,第二個文件則以包含 “3” 的行開頭。

[root@k8s-master-node1 test]# csplit 1 /3/
4
9
[root@k8s-master-node1 test]# ls
1  xx00  xx01
[root@k8s-master-node1 test]# cat xx00
1
2
[root@k8s-master-node1 test]# cat xx01
3
4
5
6

[root@k8s-master-node1 test]#

在每次出現 “3” 時分割文件:

[root@k8s-master-node1 test]# cat 1
1
2
3
3
4
5
6
[root@k8s-master-node1 test]#
[root@k8s-master-node1 test]# csplit 1 /3/ {*}
4
2
9
[root@k8s-master-node1 test]# ls
1  xx00  xx01  xx02
[root@k8s-master-node1 test]# cat xx00
1
2
[root@k8s-master-node1 test]# cat xx01
3
[root@k8s-master-node1 test]# cat xx02
3
4
5
6

[root@k8s-master-node1 test]#

{}  里面*可以替換為具體的數字,表述第幾次出現的時候開始切割

僅當內容以包含 “3” 的行開始時才復制,并且省略前面的所有內容:

[root@k8s-master-node1 test]# cat 1
1
2
1 3
4
5
6

[root@k8s-master-node1 test]# csplit 1 %3%
11
[root@k8s-master-node1 test]# ls
1  xx00
[root@k8s-master-node1 test]# cat xx00
1 3
4
5
6

[root@k8s-master-node1 test]#

將文件分割成不同大小

split 與 csplit 類似。它將文件分割成特定的大小,當您將大文件分割成小的多媒體文件或者使用網絡傳送時,速度便會快很多。

默認的大小為 1000 行

# split 1.mv
# ls -hl
266K Aug 21 16:58 xaa
267K Aug 21 16:58 xab
315K Aug 21 16:58 xac
[...]

它們分割出來的大小相似,但你可以指定任何你想要的大小。這個例子中是 10M 字節

# split -b 10M 1.mv

尺寸單位縮寫為 K,M,G,T,P,E,Z,Y(1024 的冪)或者 KB,MB,GB 等等(1000 的冪)。

為文件名自定義前綴和后綴:

# split -a 3 --numeric-suffixes=9 --additional-suffix=mine 1.mv SB
240K Aug 21 17:44 SB009mine
214K Aug 21 17:44 SB010mine
220K Aug 21 17:44 SB011mine

-a 選項控制編號的數字位置。

--numeric-suffixes 設置編號的開始值。默認前綴為 x,你也可以通過在文件名后輸入它來設置一個不同的前綴。

將分割后的文件合并

你可能想在某個時候重組你的文件。常用的 cat 命令就用在這里:

# cat SB0* > 2.txt

示例中的星號通配符將匹配到所有以 SB0 開頭的文件,但是結果可能有排查。所以使用問號通配符進行更精確的匹配,每個字符使用一個問號:

# cat SB0?????? > 2.txt


責任編輯:武曉燕 來源: 步步運維步步坑
相關推薦

2017-08-30 08:57:49

Linux分割文件重組文件

2021-12-02 08:47:40

LinuxLinux命令

2009-12-24 10:12:02

Linux查看文件編碼

2011-10-27 14:15:05

Java 7

2017-06-01 15:30:32

LinuxVim文件加密

2016-12-14 09:24:42

文件目錄壓縮

2010-03-05 09:40:08

Python遞歸

2015-08-25 15:53:08

LinuxcURL

2017-08-01 17:34:47

Linux內核驅動文件讀寫

2019-12-17 09:00:48

split分割Linux文件Linux

2011-09-13 14:25:31

Nvidia芯片移動

2011-04-14 17:03:50

Linuxsplitcat

2010-11-29 14:24:06

Linux軟件管理

2011-09-07 14:43:24

2010-08-05 09:46:45

FlexAIR文件打包

2022-08-17 12:35:26

Linux sed編輯器

2010-04-30 11:22:23

Unix系統

2010-07-01 10:20:41

SQL Server

2013-10-28 10:00:12

2020-11-30 12:32:40

PyTorch語義分割python
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: av一二三四| 亚洲啊v| 欧美电影在线观看网站 | 久久久免费少妇高潮毛片 | 中文字幕日韩欧美一区二区三区 | 国产精品久久久久久久久久妞妞 | 一级毛片免费 | 久久精品色欧美aⅴ一区二区 | 日韩一区二区久久 | 涩涩视频在线播放 | 久久久国产一区二区三区四区小说 | 草比网站 | 久久一区 | 国产精品永久 | 久久久国产一区二区 | 欧美国产精品一区二区 | 日韩三片| 中文字幕在线第一页 | 真人女人一级毛片免费播放 | 成人一区av偷拍 | av资源在线看 | 欧美一级淫片免费视频黄 | 久久综合伊人一区二区三 | 国产在线一区二区 | 日韩毛片在线观看 | 成人一区二区三区在线观看 | 亚洲第一视频 | 久久麻豆精品 | 欧美一区二区三区精品免费 | 国产激情视频网站 | 成人在线播放网站 | 国产精品久久久久久久久久久久久久 | 国产精品精品视频一区二区三区 | 久久精品欧美一区二区三区不卡 | 亚洲成人在线免费 | 成人精品一区亚洲午夜久久久 | 欧美男男videos | 色永久| 亚洲九色 | 欧美综合国产精品久久丁香 | 成人在线观看中文字幕 |