藍森林首頁 | 返回主頁 | 本站地圖 | 站內搜索 | 聯繫信箱 |
 您目前的位置:首頁 > 自由軟件 > 技術交流 > 應用編程


    

藍森林 http://www.lslnet.com 2006年6月26日 11:18


請教分割文件的高級用法

split命令可以按照每個文件的尺寸分割文件。

我有一個很多行的大文本文件。如何用split把它分成若幹份(按尺寸或者按行分)但是每行都保持完整。
也就是說同一行的內容不能被分到兩個文件中。

--------------------------------------
因為是文本文件,所以分開壓縮後每個都可以獨立使用。
如果要將分割後的小文件都通過gzip壓縮.
但是要求每個gzip壓縮後的文件都在100K左右。
這個事情怎麼做?

請教分割文件的高級用法

-b, --bytes=SIZE        put SIZE bytes per output file

  -l, --lines=NUMBER      put NUMBER lines per output file

請教分割文件的高級用法

man csplit

請教分割文件的高級用法

請教分割文件的高級用法

小弟實在是沒看明白怎麼用csplit保證分成每個文件在100K左右,而且最後一行不被分到兩個文件中。
文件有很多很多行。每行都有行尾,這可怎麼寫正則阿!

第二個gzip個不知道能不能做?

請各位老大明示。

多謝了!

請教分割文件的高級用法

那直接用split足夠了
烈火兄不是給了說明了麼
[code]split -b 100k file[/code]
自動命名為xaa、xab、xac……
拆分的文件超過26*26的話,可以加-a參數
[code]split -b 100k -a 3 file auto[/code]就表示自動命名為autoaaa、autoaab、autoaac……

請教分割文件的高級用法

csplit簡單用法:
[code]
/home/lee#cat tmp
%%%%
sadfsdf
sdfsdfsdf
sdfsdfsdf
%%%%%%
sdfsdrwr
2w34234234
werwerwe
r

w
er
w
er
%%%
sdfsdf
/home/lee#csplit -z tmp /%.*/ {*} #以%為分割符分割文件
33
49
11
/home/lee#ls xx*
xx00  xx01  xx02
/home/lee#cat xx00
%%%%
sadfsdf
sdfsdfsdf
sdfsdfsdf
/home/lee#cat xx01
%%%%%%
sdfsdrwr
2w34234234
werwerwe
r

w
er
w
er
/home/lee#cat xx02
%%%
sdfsdf
/home/lee#
[/code]
more csplit , man csplit please ;)

請教分割文件的高級用法

直接使用「split -b 100k file」
同一行的文本有可能被分到兩個文件中的。

我就是沒法解決這問題。

我要求保證每行的記錄完整。

請教分割文件的高級用法

-->
:?: :?: :?:  :em06:
貼出您的樣本,說出您要的效果!

請教分割文件的高級用法

比如這個名為aa的文本有56行每行100個字,約5601字節。
split -b 1k aa
會被分成6個文件
用tail -1 xaa和head -1 xab查看發現
應該是完整的100個零的行被分在兩個文件中了。

我希望在分文件的時候,同一行的內容不要分到兩個文件中。
要麼整行屬於前一個文件,要麼整行屬於後一個文件。
每個文件的尺寸不超過指定大小。

--------------------

000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555
666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666666
777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777777
888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888888
999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999999
000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000
111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111
222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222
333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333333
444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444444
555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555555

請教分割文件的高級用法

那就按行來分割如何呢?

請教分割文件的高級用法

為了演示我把文字寫得很整齊。實際上每行的長短差異還是挺大的。而且我要按照規範分割文件後供後續操作。所以還是要按照尺寸分割。

而且最麻煩的事情是要求:分割後的文件通過zip壓縮後尺寸在100k左右。

要是實在,搞不定就不用shell了,我另外寫程序。把尺寸控制在90K左右避免越界。


無論問題是否解決。都感謝「烈火」大大。能在這個時間還在幫兄弟,兄弟都記下了。

請教分割文件的高級用法

你用
[code]split -C 100k file[/code]

請教分割文件的高級用法

I write a shell program to split a file. It works well.
But i know it will be much better if you give me some suggestions.
[simone@localhost shell]$ cat split.sh
x="$(cat -n $1| awk '{print $1}'|tail -1)";for((y=0;y<=x-$2;y=y+$2)) do head -$(expr $y + $2) $1 | tail -$2 >"split"$y.out;done;tail -$(expr $x % $2) $1>"split"$x.out
-------------------------------------------------
arg1 : filename
arg2 : the number of rows (each file has arg2 rows)
-------------------------------------------------
for eg:

[simone@localhost shell]$ cat mm
simone 12 girl kkpl 15
elizaebth 13 boy fu 13
mary 15 girl kk 12
kily 20 ff oo 15
mimi 16 gg jj 17
kiki 10 ll qq 11
lily 4 op fight 3
kate 22 leader yes 23
CU 12 clerik no 10
XP 13 jo wiki 33
lilou 15 kj dj 11
kKK 13 girl boy 12
L 20 boy girl 17
                                                                                                           
[simone@localhost shell]$ ./split.sh mm 4
[simone@localhost shell]$ dir
mm  split0.out  split14.out  split4.out  split8.out  split.sh
[simone@localhost shell]$ cat split0.out split4.out split8.out split14.out
simone 12 girl kkpl 15
elizaebth 13 boy fu 13
mary 15 girl kk 12
kily 20 ff oo 15
mimi 16 gg jj 17
kiki 10 ll qq 11
lily 4 op fight 3
kate 22 leader yes 23
CU 12 clerik no 10
XP 13 jo wiki 33
lilou 15 kj dj 11
kKK 13 girl boy 12
L 20 boy girl 17



Copyright © 1999-2000 LSLNET.COM. All rights reserved. 藍森林網站 版權所有。 E-mail : webmaster@lslnet.com