- 论坛徽章:
- 0
|
原帖由 walkerxk 于 2008-7-22 22:49 发表 ![]()
是要-----上下各一行么?
grep -C 1 '-----' a.txt
这样不行啊,因为……部分的文字中,也会含有'----'字符呢
我用下面的办法碰到了些问题,请指点
源文件行号和对应的内容如下
186 -------------------------------------------------------------
187 ^LSQL ordered by Reads for DB: NODE1 Instance: node1 Snaps: 1 -2
188 -> End Disk Reads Threshold: 1000
189
190 CPU Elapsd
191 Physical Reads Executions Reads per Exec %Total Time (s) Time (s) Hash Value
192 --------------- ------------ -------------- ------ -------- --------- ----------
193 0 56 0.0 0.0 0.07 0.04 633914867
194 select q_name, state, delay, expiration, rowid, msgid, dequeu
###一、找出匹配的行号
<oracle@shadow:/home/oracle>v_a=`cat sp*|awk '/Physical Reads Executions/{print NR}'|head -1`
<oracle@shadow:/home/oracle>echo $v_a
191
###测试,取出字段名称,输出到结果文件
cat sp*|awk 'NR==191 {print $1,$2,$3}'>result.csv
<oracle@shadow:/home/oracle>cat result.csv
Physical Reads Executions
###二、找出他的下两行的行号,即字段的值
<oracle@shadow:/home/oracle>v_b=`expr $v_a + 2`
<oracle@shadow:/home/oracle>echo $v_b
193
###测试,输出结果
<oracle@shadow:/home/oracle>cat sp*|awk 'NR==193 {print $1,$2,$3}'
0 56 0.0
###取出字段名称,输出到结果文件
<oracle@shadow:/home/oracle>cat sp*|awk 'NR==193 {print $1,$2,$3}'>>result.txt
<oracle@shadow:/home/oracle>cat result.csv
Physical Reads Executions
0 56 0.0
问题出在这!当要打印这一行(用变量传入行号)的时候,为什么没结果输出呢?
<oracle@shadow:/home/oracle>cat sp*|awk 'NR==$v_b'
<oracle@shadow:/home/oracle>
[ 本帖最后由 yuanfang830 于 2008-7-22 23:31 编辑 ] |
|