将大文件分割成小文件
如何使用 Tcl 将一个大文件拆分为 n 个小文件?要分割的文件名和要创建的文件数量必须通过命令行给出。这是我到目前为止所拥有的:
proc splitter { file no } {
set lnum 0
set file_open [open $file r]
while {[gets $file_open line] >= 0 } {
incr lnum
}
puts "$lnum"
set num [expr $lnum/$no]
close $file_open
}
How can I split a huge file into n number of smaller files using Tcl? The file name to split and number of files to be created have to be given through command line. Here is what I have so far:
proc splitter { file no } {
set lnum 0
set file_open [open $file r]
while {[gets $file_open line] >= 0 } {
incr lnum
}
puts "$lnum"
set num [expr $lnum/$no]
close $file_open
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是分割文本文件的一种方法,其优点是不会一次在内存中保存太多内容。 (也可以拆分二进制文件,但是需要使用
read
而不是gets
,并且还要考虑数据中是否存在记录边界;文本大多更简单.)Here is one way to split text files, which has the advantage of not holding much in memory at once. (You can also split binary files, but then you need to use
read
instead ofgets
, and also to consider whether there are record boundaries in the data; text is mostly simpler.)argv
数组访问命令行参数seek
返回到文件顶部。exec< /code>
调用
split
?argv
array to access command line parametersseek
back to the top of the file.exec
to call out tosplit
?