问题描述
我有一个文件A和B。
- A包含日志条目
- B包含一些行号这又是一些具体的行号
指日志文件
我有一个awk程序是这样的:
I have an awk program like this:
echo "($(awk 'NR==1{r1=$1;next}
NR>2{printf"||"}
{printf"(NR>%d&&NR<%d)",r1,$1;r1=$1}' B))&&/mypattern/"|
awk -f- A
---> (courtesy jeff y from stack flow )
之前的部分|产生的范围进行文件搜索A.
例如: <$c$c>(NR>385&&NR<537)||(NR>537&&NR<539)||(NR>539&&NR<547)|$c$c>
这些都是一些可以由之前的部分来产生范围|
我需要存储哪些mypattern在九月的文件ORA变量有匹配范围最后吃
说如 NR&GT; 385安培;&安培; NR&LT; 537
- >根据我的模式这个范围的文件中的可能没有比赛,其中作为( NR&GT; 539安培;&安培; NR&LT; 547
这可能
所以任何想法来检查是否匹配已经发生了,如果是这样存储对应侧NR值的文件的NR。
the part before the "|" generates the ranges to be search in file A.eg : (NR>385&&NR<537)||(NR>537&&NR<539)||(NR>539&&NR<547)|
these are some of the ranges which can be generated by the part before "|"I need to store the ranges for which "mypattern" has a match in a sep file ora variable ate lastsay eg NR>385&&NR<537
--> this range on file A may not have a match according to my pattern where as (NR>539&&NR<547
this may have so any idea to check whether a match had happened , if so to store the NR corresponding NR values in side a file .
推荐答案
由于您的澄清意见,我将提出一个解决方案,只需要一个穿过FILE_A使用awk,而不是试图提取和使用行号和数字范围(FILE_B)在多遍:
Given your clarification in comments, I would propose a solution that only takes one pass through FILE_A with awk, rather than trying to extract and use line numbers and ranges numerically (FILE_B) in multiple passes:
awk '/Exception/ && !/ExceptionUnparseable date/ {
haveEx="yes"; ex=$0; exDate=last; haveMatch=""}
haveEx && /tms/ {
haveMatch="yes"; print exDate; print ex; haveEx=""}
haveMatch && /tms/ {print}
{last = $0} ' FILE_A
或者,如果你不需要看那些匹配模式的行:
Or, if you don't need to see the lines that do match the pattern:
awk '/Exception/ && !/ExceptionUnparseable date/ {
haveEx="yes"; ex=$0; exDate=last}
haveEx && /tms/ {
print exDate; print ex; haveEx=""}
{last = $0} ' FILE_A
这篇关于检测场的范围 - shell脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!