linux中split命令的重要用途------文件分割

这篇博客介绍了Linux中的split命令,用于将文件按行或字节大小进行分割。通过示例展示了如何使用-split -l指定行数、-d使用数字后缀、-a设置后缀位数以及定义文件前缀进行文件拆分。split命令在实际开发中对于文件处理非常实用。
摘要由CSDN通过智能技术生成

      最近准备写个文件分割的工具, 跟同事交流后, 发现linux早已提供了这个命令,来一起看下:

taoge@localhost Desktop> ls
a.txt
taoge@localhost Desktop> cat a.txt 
3576661317
3577352199
3577724088
3578367381
3578587869
3579287088
3581127558
3582079011
3582736026
3585019998
taoge@localhost Desktop> filename="a.txt"
taoge@localhost Desktop> rm test_* -f
taoge@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> ls
a.txt  test_0000  test_0001  test_0002
taoge@localhost Desktop> wc -l test*
  4 test_0000
  4 test_0001
  2 test_0002
 10 total
taoge@localhost Desktop> 
       注意, 如下命令我是批量赋值到linux命令终端的:

  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值