最近需要编写一套shell脚本以实现某些新编的Tools的automatic检测,遇到了这样一个问题:A执行输出结果中的某些特定内容要作为B的参数,A的输出大概是这样的
1 abcdefg.......
2
3 TTtttt.......
4
5 Ssssssss.......
6
7 def def def .......
8
9 XXX succ.......
10
11 Name of loaded key:
12 00 0b 02 f8 92 48 13 bb 77 b1 f8 7c ea 4b 2f dc
13 45 a9 8e 7a 5e ae 38 80 83 1c 13 92 c7 c6 ba 35
14 96 d6
15
16
17 Loaded key handle: 80000000
18
19 Abcdefg.......
20
21 ........
其中得到的这一串loaded key即是需要的, 同时需要转换成000b02f8924813bb77b1f87cea4b2fdc45a98e7a5eae3880831c1392c7c6ba3596d6的格式才符合参数要求。一时有点犯怵。。。
研究了下sed,awk之类,暂且得到了这么一个办法(也许不是最好的):
grep -A 3 "Name of loaded key:"output.txt|tr "\n" " " >grep.txt
A=`sed -e 's/ //g' grep.txt | awk -F':' '{print $2}'`