Linux切割txt文件,Linux切割命令split ,可以切割日志文件,文本文件

一.split说明

split可以用来切割一个日志文件,这样便于处理日志。比如有一个12G的日志,需要删除某一行数据,知道行号,但用sed和vi比较慢,

就可以先用  split 切割 ,然后再删除那行,最后再重组合

二.使用说明

[root@bogon Desktop]# split --help

Usage: split [OPTION] [INPUT [PREFIX]]

Output fixed-size pieces of INPUT to PREFIXaa, PREFIXab, ...; default

size is 1000 lines, and default PREFIX is `x'.  With no INPUT, or when INPUT

is -, read standard input.

Mandatory arguments to long options are mandatory for short options too.

-a, --suffix-length=N   use suffixes of length N (default 2)

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

-C, --line-bytes=SIZE   put at most SIZE bytes of lines per output file

-d, --numeric-suffixes  use numeric suffixes instead of alphabetic

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

--verbose           print a diagnostic to standard error just

before each output file is opened

--help     display this help and exit

--version  output version information and exit

SIZE may have a multiplier suffix: b for 512, k for 1K, m for 1 Meg.

-a  切割后的文件名的后几位,用几位数字表示。默认是两位

-b  切割后的文件的大小

-C  切割后的文件每行多少字节数

-d  切割后的文件名的后几位用数字代替字母。默认是字母xx

-l   切割后的文件,每个文件都少行

三.举例说明

1.产看文件

[root@bogon Desktop]# ll

total 388

-rw-r--r-- 1 root root   4803 Feb 26  2009 gnome-terminal.desktop

-rw-r--r-- 1 root root 349027 May  5 04:06 mysql_data.gz

-rw------- 1 root root   1108 Apr 25 19:23 new file

drwxrwxrwx 2 root root   4096 Apr 24 06:39 NFS

-rw-r--r-- 1 root root    285 May  5 22:02 split.log

2.切割后文件名后缀为3个字母

[root@bogon Desktop]# split -a 3  split.log

[root@bogon Desktop]# ll

total 396

-rw-r--r-- 1 root root   4803 Feb 26  2009 gnome-terminal.desktop

-rw-r--r-- 1 root root 349027 May  5 04:06 mysql_data.gz

-rw------- 1 root root   1108 Apr 25 19:23 new file

drwxrwxrwx 2 root root   4096 Apr 24 06:39 NFS

-rw-r--r-- 1 root root    285 May  5 22:02 split.log

-rw-r--r-- 1 root root    285 May  5 23:16 xaaa

3.切割后文件名后缀为3个字母,切割后的文件,每个文件两行内容,

[root@bogon Desktop]# split -a 3 -l 2 split.log

[root@bogon Desktop]# ll

total 412

-rw-r--r-- 1 root root   4803 Feb 26  2009 gnome-terminal.desktop

-rw-r--r-- 1 root root 349027 May  5 04:06 mysql_data.gz

-rw------- 1 root root   1108 Apr 25 19:23 new file

drwxrwxrwx 2 root root   4096 Apr 24 06:39 NFS

-rw-r--r-- 1 root root    285 May  5 22:02 split.log

-rw-r--r-- 1 root root     76 May  5 23:17 xaaa

-rw-r--r-- 1 root root    109 May  5 23:17 xaab

-rw-r--r-- 1 root root    100 May  5 23:17 xaac

4.切割后文件名后缀为3个(位)数字,切割后的文件,每个文件两行内容,

[root@bogon Desktop]# split -a 3 -l 2 -d  split.log

[root@bogon Desktop]# ll

total 436

-rw-r--r-- 1 root root   4803 Feb 26  2009 gnome-terminal.desktop

-rw-r--r-- 1 root root 349027 May  5 04:06 mysql_data.gz

-rw------- 1 root root   1108 Apr 25 19:23 new file

drwxrwxrwx 2 root root   4096 Apr 24 06:39 NFS

-rw-r--r-- 1 root root    285 May  5 22:02 split.log

-rw-r--r-- 1 root root     76 May  5 23:17 x000

-rw-r--r-- 1 root root    109 May  5 23:17 x001

-rw-r--r-- 1 root root    100 May  5 23:17 x002

-rw-r--r-- 1 root root     76 May  5 23:17 xaaa

-rw-r--r-- 1 root root    109 May  5 23:17 xaab

-rw-r--r-- 1 root root    100 May  5 23:17 xaac

四.参考

man split

声明:本文档可以随意更改,但必须署名原作者

作者:凤凰舞者 qq:578989855

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值