unix shell 通过两个行号获取文件内容 比如获取1.log文件的10000行到20000行 请问怎么写 请高手赐教 谢谢
发布网友
发布时间:2022-04-23 09:52
我来回答
共1个回答
热心网友
时间:2023-10-10 05:30
with Gnu sed, you can do something like this
sed -n '10000,20000p' yourfile
testing
User@User-PC ~
$ sed --version
GNU sed version 4.1.5
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,
to the extent permitted by law.
User@User-PC ~
$ cat bin/temperature
#! /usr/bin/perl
use strict;
use warnings;
use LWP::Simple;
my ($url, $content, @x, $x, @y);
$url = "http://wap.weather.gov.hk";
$content = get($url) or die;
@x = split /\n/, $content;
@y = grep /^[\w\d]+/, @x;
$x = join "\n", @y;
$x =~ s/<[^>]+>//g;
print "$x\n"
User@User-PC ~
$ sed -n '3,9p' bin/temperature
use strict;
use warnings;
use LWP::Simple;
my ($url, $content, @x, $x, @y);
$url = "http://wap.weather.gov.hk";
User@User-PC ~
$
User@User-PC ~
$ wc -l < mil-dic.txt
83337
User@User-PC ~
$ sed '10000,20000!d' mil-dic.txt
<skipped>
97fa7920
97jetta
97probe
98
980108042
980125
9803735395
980381
980480
980517
9805d4
9807013131
User@User-PC ~
$
OK? :)