unix shell 通过两个行号获取文件内容 比如获取1.log文件的10000行到20000行 请问怎么写 请高手赐教 谢谢

来源:百度知道 编辑:UC知道 时间:2024/07/05 05:02:22
pa=$(pwd)
aa=$(date +"%d %H:%M")
echo $aa
cp $pa/nohup.out $pa/nohup1.log
grep -n "23 13:05" nohup1.log|awk -F":" '{print $1}' > 1.log
n=$(head -1 $pa/1.log)
s=$(wc -l nohup1.log|awk '{print $1}')
echo $s
echo $n
s=$((s-n+3))
echo $s
tail -n $s $pa/nohup1.log>1.log

tail -n 获取的内容不全 比如获取10000条内容 tial -n只能获取3百多条
获取的不全 请高手赐教

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-