关于数据检索的问题
我想通过关键字去检索某文件,然后取得它的倒数第二行。如何实现。
例子
我的文件的内容是:
2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-8109-23) index=0
2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-8109-23) event key=txt_dealer_code
2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-8109-23) event value=40512108
2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-8109-23) index=0
2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-8109-23) event key=txt_password
2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-8109-23) event value=a
2011-06-04 11:33:20,356 INFO [STDOUT] (ajp-8109-23) dao parameter=0
2011-06-04 11:33:20,356 INFO [STDOUT] (ajp-8109-23) key=txt_dealer_code
2011-06-04 11:33:20,356 INFO [STDOUT] (ajp-8109-23) value=40512108
2011-06-04 11:33:20,356 INFO [STDOUT] (ajp-8109-23) dao parameter=1
2011-06-04 11:33:20,356 INFO [STDOUT] (ajp-8109-23) key=txt_password
我的关键是字是:“event key=txt_password”
我想取得的行是:2011-06-04 11:33:20,355 INFO [STDOUT] (ajp-172.25.1.80-8109-23) event value=40512108
[解决办法]
a=$(sed -n '/event key=txt_password/=' file)
((a=a-2))
sed -n "%a p" file