使用Perl批量读取文件最后行
2024-08-31 19:25:17
使用Perl批量读取文件最后行
面对成百上千个文件,有时我们需要查看它的最后行,单个文件打开将耗费大量时间,而通过Perl提取出最后行,将快速的帮助我们处理繁琐的事务。
特性
整个目录完全遍历,自动提取最后行
提取出的文件结构
Perl代码
#!/usr/bin/perl
use warnings;
###########################################
#./readlast_line.pl log/
###########################################
my $indir = $ARGV[0];
opendir DIR, $indir or die "Connot open $indir: $!";
unlink "temp_line";
open(OUTFILE, ">>temp_line") || die ("Could not open file temp_line ! \n");
foreach my $file (sort readdir DIR){ #遍历目录下的文件
if($file =~ /^\./){
next;
}
#print "$indir$file\n";
print OUTFILE "\t\t $indir$file \t\t \n"; #输出文件名及其路径
my $last_line = `tail -10 $indir$file`; #反引号捕获
print OUTFILE "$last_line \n";
print OUTFILE "\n\n\n"; #分割不同文件之间的换行
}
close OUTFILE;
rename 'temp_line','filelast_line';
print "\nOutput file: filelast_line\n";
最新文章
- CentOS7下安装mysql5.6修改字符集为utf8并开放端口允许远程访问
- ES6之const命令
- 使用canvas实现擦玻璃效果---转载
- Eclipse学习记录
- 分享我设计的iOS项目目录结构
- JavaScriptResult用法
- OOA、OOD、OOP
- Eclipse Removing obsolete files from server 问题
- 转 intValue()的用法
- ef mysql
- IT公司PM沟通那儿些事(一)
- python基础 ---- 安装
- SQL IN 操作符
- Spring SpringBoot和SpringCloud的关系
- dd 命令的使用
- 自定义MVC框架之工具类-文件上传类
- linq 根据指定条件返回集合中不重复的元素
- SQL Server SqlCacheDependency 缓存依赖
- matlab一些函数
- 4G模块ME3760_V2的拨号过程
热门文章
- *android抓包工具——fiddler抓包分析api接口
- 通过wireshark,以及python代码收发邮件,了解smtp协议,pop协议工作过程
- <;memory>;(包括了auto_ptr,shared_ptr等各种指针)
- Oracle Sqlplus中上下键出现^[[A乱码问题
- php中ajax使用实例
- jodd-cache集锦
- AJAX - 封装的传参改为传入对象 XML JSON 数据格式
- 如何优雅的写UI——(1)MFC六大核心机制-程序初始化
- Android: 分页浏览的利器 android View Pager
- 86.八千万qq密码按相似度排序并统计密码出现次数,生成密码库