csplit命令分割文件用法

在linux的使用中,有时需要对文件进行分割处理,csplit命令,可以帮助我们灵活的处理分割文件,以下为用法说明:

用法:csplit [选项]... 文件 格式...
Output pieces of FILE separated by PATTERN(s) to files 'xx00', 'xx01', ...,
and output byte counts of each piece to standard output.

如果文件为“-”,则读取标准输入。

必选参数对长短选项同时适用。
  -b, --suffix-format=FORMAT  use sprintf FORMAT instead of %02d
  -f, --prefix=PREFIX        use PREFIX instead of 'xx'
  -k, --keep-files           do not remove output files on errors
      --suppress-matched     suppress the lines matching PATTERN
  -n, --digits=数位        使用指定的进制数位代替二进制
  -s, --quiet, --silent    不显示输出文件的尺寸计数
  -z, --elide-empty-files    删除空的输出文件
      --help        显示此帮助信息并退出
      --version        显示版本信息并退出

Each PATTERN may be:
  INTEGER            copy up to but not including specified line number
  /REGEXP/[OFFSET]   copy up to but not including a matching line
  %REGEXP%[OFFSET]   skip to, but not including a matching line
  {INTEGER}          repeat the previous pattern specified number of times
  {*}                repeat the previous pattern as many times as possible

A line OFFSET is a required '+' or '-' followed by a positive integer.

用法示例:

[genesis@localhost test]$ more data.txt
hhhh
GGGG
HI01
III
HI02
HI01
1223
6666

####将文件从第二行进行分割

[genesis@localhost test]$ csplit -f ss data.txt 2
5
34
[genesis@localhost test]$ ls
data.txt  ss00  ss01
[genesis@localhost test]$ more ss00 ss01
::::::::::::::
ss00
::::::::::::::
hhhh
::::::::::::::
ss01
::::::::::::::
GGGG
HI01
III
HI02
HI01
1223
6666

##按照匹配模式分割
[genesis@localhost test]$ csplit -f ss data.txt /HI01/+1 /HI02/
15
4
20
[genesis@localhost test]$ ls
data.txt  ss00  ss01  ss02
[genesis@localhost test]$ more ss00 ss01 ss02
::::::::::::::
ss00
::::::::::::::
hhhh
GGGG
HI01
::::::::::::::
ss01
::::::::::::::
III
::::::::::::::
ss02
::::::::::::::
HI02
HI01
1223
6666

##多模式匹配分割

[genesis@localhost test]$ csplit -f ww data.txt /HI01/+1 /HI01/ /1223/
15
9
5
10
[genesis@localhost test]$ ls
data.txt  ww00  ww01  ww02  ww03
[genesis@localhost test]$ more ww00 ww01 ww02 ww03
::::::::::::::
ww00
::::::::::::::
hhhh
GGGG
HI01
::::::::::::::
ww01
::::::::::::::
III
HI02
::::::::::::::
ww02
::::::::::::::
HI01
::::::::::::::
ww03
::::::::::::::
1223
6666

##指定分割后文件数字位数

[genesis@localhost test]$ csplit -f ff data.txt -n 3 /HI01/
10
29
[genesis@localhost test]$ ls
data.txt  ff000  ff001
[genesis@localhost test]$ more ff000 ff001
::::::::::::::
ff000
::::::::::::::
hhhh
GGGG
::::::::::::::
ff001
::::::::::::::
HI01
III
HI02
HI01
1223
6666

##制定分割后文件名及后缀

[genesis@localhost test]$ csplit -f ff data.txt -b %03d.txt %HI01%
29
[genesis@localhost test]$ ls
data.txt  ff000.txt
[genesis@localhost test]$ more ff000.txt
HI01
III
HI02
HI01
1223
6666

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值