如何使用 Perl 读取文件中两行之间的所有行? [英] How can I read all of the lines between two lines in a file, using Perl?

查看:49
本文介绍了如何使用 Perl 读取文件中两行之间的所有行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文件,其内容如下:

I have one file where the contents looks like:

pch
rch
channel
cap
nch
kappa
.
.
.
kary
ban
....

现在我想将我的文件从 nch 读取到 kary 并仅将这些行复制到其他文件中.我怎样才能在 Perl 中做到这一点?

Now I want to read my file from nch to kary and copying those lines only in some other file. How can I do this in Perl?

推荐答案

如果我正确理解你的问题,这很简单.

If I understand your question correctly, this is pretty simple.

    #!perl -w
    use strict;
    use autodie;

    open my $in,'<',"File1.txt";
    open my $out,'>',"File2.txt";

    while(<$in>){
    print $out $_ if /^nch/ .. /^kary/;
    }

这篇关于如何使用 Perl 读取文件中两行之间的所有行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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