Perl:如何在不读取和复制整个文件的情况下删除文件的第一行 [英] Perl: How do I remove the first line of a file without reading and copying whole file

查看:122
本文介绍了Perl:如何在不读取和复制整个文件的情况下删除文件的第一行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在目录中确实有一堆文件,并且我想从每个文件中删除第一行(包括回车符).我可以将整个文件读取为字符串数组,并将除第一个元素以外的所有内容写入新文件,但是对我来说有点麻烦,是否有更好的方法?哦,首选的语言是Perl.

I do have a whole bunch of files in a directory and from every file I want to remove the first line (including carriage return). I can read the whole file into an array of strings and write all but the first element to a new file, but that looks a bit cumbersome to me are there better ways? Oh the prefered language is Perl.

推荐答案

尝试使用此衬套

perl -pi -e '$_ = "" if ( $. == 1 );' filename

我以前用过它,应该是您所需要的.

I've used it before, should be all you need.

这篇关于Perl:如何在不读取和复制整个文件的情况下删除文件的第一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆