Chinaunix首页 | 论坛 | 博客
  • 博客访问: 27745
  • 博文数量: 9
  • 博客积分: 45
  • 博客等级: 民兵
  • 技术积分: 57
  • 用 户 组: 普通用户
  • 注册时间: 2006-06-12 13:59
文章分类
文章存档

2012年(9)

我的朋友

分类:

2012-06-04 17:15:30

原创作品,允许转载,转载时请务必以超链接形式标明文章 原始出处 、作者信息和本声明。否则将追究法律责任。http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3184084
有系统运维的过程中,日志文件往往非常大,这样就要求对日志文件进行分割,在此特用shell脚本对文件进行分割
方法一:
#!/bin/bash

linenum=`wc -l httperr8007.log| awk '{print $1}'`
n1=1
file=1
while [ $n1 -lt $linenum ]
do
n2=`expr $n1 + 999`
sed -n "${n1}, ${n2}p" httperr8007.log > file_$file.log
n1=`expr $n2 + 1`
file=`expr $file + 1`
done
其中httperr8007.log为你想分割的大文件,file_$file.log 为分割后的文件,最后为file_1.log,file_2.log,file_3.log……,分割完后的每个文件只有1000行(参数可以自己设置)
方法二:
split 参数:
-b :后面可接欲分割成的档案大小,可加单位,例如 b, k, m 等;
-l :以行数来进行分割;
#按每个文件1000行来分割除
split -l 1000 httperr8007.log httperr
httpaa,httpab,httpac ........
#按照每个文件100K来分割
split -b 100k httperr8007.log http
httpaa,httpab,httpac ........

本文出自 “聆听未来” 博客,请务必保留此出处http://blog.chinaunix.net/space.php?uid=9419692&do=blog&id=3184084

阅读(261) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~