
可以使用以下命令来实现在Shell中查出文件行号
减1的 *** 作:
```
awk 'NR==LINE-1 {print $0; exit}' FILE_NAME
```
将上述命令中的LINE替换为需要查找的行号即可。该命令使用awk命令,NR表示当前行号,$0表示当前行内容,print $0表示输出当前行内容。通过对NR进行判断,找到需要查找的行并输出内容。使用exit命令退出循环。由于你需要输出的是查找到的行的上一行内容,因此需要将查找到的行号减一。FILE_NAME表示需要查找的文件名。
例如,如果需要查找文件testtxt中第5行的上一行内容,可以使用以下命令:
```
awk 'NR==4 {print $0; exit}' testtxt
```
上面的命令会输出testtxt中第4行的内容,即第5行的上一行。
something like this
sed -n '10000,20000p' yourfile
testing
User@User-PC ~
$ sed --version
GNU sed version 415
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 = "";
$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 = "";
User@User-PC ~
$
User@User-PC ~
$ wc -l < mil-dictxt
83337
User@User-PC ~
$ sed '10000,20000!d' mil-dictxt
<skipped>
97fa7920
97jetta
97probe
98
980108042
980125
9803735395
980381
980480
980517
9805d4
9807013131
User@User-PC ~
$
OK :)
我告诉你命令,你自己写
sed -n “5,10p” file ==>指定从第5行到第十行
egrep "\<abc\>" file ==>在file中查找abc这个单词(指定的字段)
检查一下当前的$SHELL
我试了一下bash可以这么给变量赋值,而sh则会报跟你一样的错误,如下
# rows=5000;
rows=5000: Command not found
# echo $SHELL
/sbin/sh
# bash
bash-32# rows=5000;
bash-32# echo $rows
5000


评论列表(0条)