sed -n 显示行号中使用变量的问题

来源:互联网 发布:视频点播php源码 编辑:程序博客网 时间:2024/05/01 10:03

sed -n 显示行号中使用变量的问题http://www.ajaxstu.com/Shellbiancheng/192339.html

cbs20
sed -n 显示行号中使用变量的问题

这样一个脚本 http://www.ajaxstu.com/Shellbiancheng/192339.html

ls ${path}20160911223*|sort | sed -n ''$t2','$(($t2+50))'p'  | while read line
do
echo $line
`zcat $line |awk -F '|' '{if ($1~18637105120) print $0}' >> /home/unicomlabs/zhengzhoutime0.txt` &
done
 

cat test.txt

123
234
345
542
adb
lsnd


我想打印每个文件除了最后两行的数据,脚本如下:


#!/bin/sh

line1=`wc -l test.txt`
line2=`expr $line1 - 2`

sed -n '1,$line2p' test.txt

因为test.txt大小会变,想通过一个变量实现,在sed 显示行号中无法使用变量
好像$line2p看成了一个变量了...

fox_fox
sed -n '1,'$line2'p' test.txt

这样应该就可以了

r2007
$line2p---->${line2}p
置顶十三问里有说明

cbs20
[quote]
sed -n '1,'$line2'p' test.txt
[/quote]

可以的,非常谢谢。

[quote]
$line2p---->${line2}p
[/quote]
好像不行
以下提示:
sed: -e expression #1, char 6: Extra characters after command

不好意思,以前看过十三问,没有仔细读 :)

waker
不行是你没看懂什么意思

sed -n 1,${line2}p  test.txt

cbs20
sed -n 1,${line2}p  test.txt

sed -n '1,${line2}p'  test.txt
我给加了引号了~
0 0
原创粉丝点击