当前位置: 技术问答>linux和unix
shell 对字段的反向查找
来源: 互联网 发布时间:2016-07-22
本文导语: 本帖最后由 shenghuiping2001 于 2009-12-14 20:40:24 编辑 有如下文件: SCHEDULE SSUNSYDDB14#PAUSU_ALS_BK_D16 ON RUNCYCLE RULE1 "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR" UNTIL 0550 +2 DAYS CARRYFORWARD : ... ... XYUNSYDDB14#PAUSU_ALS_BK_CP_MV_FILE_IMIR ...
SCHEDULE SSUNSYDDB14#PAUSU_ALS_BK_D16
ON RUNCYCLE RULE1 "FREQ=WEEKLY;INTERVAL=1;BYDAY=MO,TU,WE,TH,FR"
UNTIL 0550 +2 DAYS
CARRYFORWARD
:
...
...
XYUNSYDDB14#PAUSU_ALS_BK_CP_MV_FILE_IMIR
AT 0500 +1 DAYS UNTIL 1200 +1 DAYS
OPENS SSUNSYDDB14#"/var/opt/transfer/cache/ask"
过程:
我使用变量定位到:PAUSU_ALS_BK_CP_MV_FILE_IMIR
然后我想向上查找ON RUNCYCLE,并把向上查找的第一个ON RUNCYCLE 打印出来,不知道是用AWK 还是SED 呀?
大家帮帮忙。。
|
awk '/ON RUNCYCLE/,/PAUSU_ALS_BK_CP_MV_FILE_IMIR/' b.txt|head -1
|
sed -n '/ON RUNCYCLE/,/PAUSU_ALS_BK_CP_MV_FILE_IMIR/{/ON RUNCYCLE/=}' | tail -n1
|
UNIX平台命令很奇怪,LINUX用多了
awk '/ON RUNCYCLE/,/PAUSU_ALS_BK_CP_MV_FILE_IMIR/{if($0~/ON RUNCYCLE/)print NR}' | tail -1
再不行就写脚本吧
awk '/ON RUNCYCLE/,/PAUSU_ALS_BK_CP_MV_FILE_IMIR/{if($0~/ON RUNCYCLE/)print NR}' | tail -1
再不行就写脚本吧