linux中split命令的重要用途------文件分割
来源:互联网 发布:linux系统启动u盘制作 编辑:程序博客网 时间:2024/05/22 17:45
最近准备写个文件分割的工具, 跟同事交流后, 发现linux早已提供了这个命令,来一起看下:
taoge@localhost Desktop> lsa.txttaoge@localhost Desktop> cat a.txt 3576661317357735219935777240883578367381357858786935792870883581127558358207901135827360263585019998taoge@localhost Desktop> filename="a.txt"taoge@localhost Desktop> rm test_* -ftaoge@localhost Desktop> total=`cat $filename | wc -l`taoge@localhost Desktop> onefile=$(( $total / 3 + 1))taoge@localhost Desktop> split -l $onefile $filename -d -a 4 "test_"taoge@localhost Desktop> taoge@localhost Desktop> taoge@localhost Desktop> lsa.txt test_0000 test_0001 test_0002taoge@localhost Desktop> wc -l test* 4 test_0000 4 test_0001 2 test_0002 10 totaltaoge@localhost Desktop>注意, 如下命令我是批量赋值到linux命令终端的:
filename="a.txt"rm test_* -ftotal=`cat $filename | wc -l`onefile=$(( $total / 3 + 1))split -l $onefile $filename -d -a 4 "test_"如果你喜欢, 搞个脚本肯定是最好的啦。
我们回头看一下, 上述命令把a.txt文件按行等分地拆成了3个文件, 最重要的命令是:split -l $onefile $filename -d -a 4 "test_" ,其中-l表示按行, onefile是行数, filename是文件名, -d表示拆分后文件的后缀采用数字的形式, 如0002, -a是规定这个数字的长短, test_是拆分后文件的前缀。 很好懂。
如果要按照文件字节大小拆分, 那该怎么搞起呢? 很简单:split -b 5k a.txt -d -a 3 good_
split非常非常实用, 在很多实际开发中, 经常需要对文件进行拆分, 然后分开处理, 在后续文章中, 我们将继续介绍split的重要用途。
0 0
- linux中split命令的重要用途------文件分割
- linux split命令分割文件
- “Linux文件的合并、排序和分割” 之 split 命令
- linux大文件分割 split命令
- linux大文件分割 split命令
- linux split命令分割大文件
- Linux使用split命令分割大文件
- split分割文件命令
- linux split 命令 分割
- Linux split --分割文件
- linux split分割大文件的用法
- Linux命令学习之路---文件分割(split)命令
- split命令分割大文件
- Linux系统下使用split命令分割大文件.txt
- Linux命令-----文件分割与合并:split&cat
- Linux系统下使用split命令分割大文件
- Linux系统下使用split命令分割大文件
- Linux文件分割与合并:split & cat命令
- c语言==项目阶段性问题(27)
- 4567: [Scoi2016]背单词
- vivaldi + xmark + lastpass
- 【LeetCode】 283. Move Zeroes
- IOS学习之旅之6 控制旋转和新建storyboard进行布局拆分
- linux中split命令的重要用途------文件分割
- jdbc批量处理
- hdu 2509 Be the Winner (Anti-SG游戏+Multi-SG游戏)
- 【spring+mybatis】MyBatis-Spring-SqlSessionFactoryBean
- Ubuntu安装android源码编译工具
- 【LeetCode】 290. Word Pattern
- sql(join on 和where的执行顺序)
- 数据完整性及多表查询
- 【git】git 常用命令及使用方法