从文件中删除第一行和最后一行
我是 PHP 新手,我有数千条记录需要分析。看来每条记录的前两行和最后一行需要删除。是否有某种类型的行计数函数可以用来将每一行放入数组中,然后删除前两行,并像最大计数一样获取最后一行,然后删除它?我很茫然,感谢任何帮助。谢谢。
I am brand new to PHP and I have thousands of records I need to analyze. It appears that the first 2 lines and the last line of each record need to be removed. Is there some type of line count function that I could use to put each line into an array and then delete the first two and do like a max count to get the last line and then delete that? I am at a loss and appreciate any help. Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
假设您在 Unix/Linux 主机上,您最好使用一些简单的 shell 工具来完成此操作。具体来说是
wc -l
、head
和tail
。未经测试,YMMV 等...但应该传达这个想法。
Assuming you're on a Unix/Linux host, you'd be better off using some simple shell tools to do this for you. Specifically
wc -l
,head
, andtail
.not tested, YMMV, etc... but should get the idea across.