Notepad ++查找所有带有开括号但没有小括号的行,并为AWK脚本错误添加更小括号 [英] Notepad++ find all lines with open parentheses but no close parentheses and add closer parentheses for AWK script error

查看:342
本文介绍了Notepad ++查找所有带有开括号但没有小括号的行,并为AWK脚本错误添加更小括号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有几个大型日志文件,其中包含以下格式的行:

I have several large log files that include lines in the following format:

/resource/text_(moretext 

现在这些文件都需要用)"关闭,但是文件太大了,无法手动执行.不幸的是,这些行中的文本可以是任何东西.因此,我想我需要一个能够找到所有具有("而没有)"的行的表达式.然后,这些行必须替换为完全相同的内容,但最后要添加)".

Now these need to be closed with a ")", but the file is way too large to do this manually. Unfortunately the text within the lines can be anything. So I think I need some expression that is able to find all lines that have "(" and no ")". Then these lines have to be replaced with the exact same content but with ")" added to the end.

所以它应该像这样:

之前:

/resource/text_(moretext 

之后:

/resource/text_(moretext) 

我觉得在Notepad ++中使用正则表达式应该可以实现,但是我很难弄清楚该怎么做.

I feel like this should be possible in Notepad++ using regular expressions, but I have a hard time figuring out how to do this.

我需要这个,因为我正在将这些日志与.TTL文件进行比较,以提取两个文件中都可以找到的行.我使用以下AWK脚本执行此操作:

I need this because I am comparing these logs to a .TTL file to extract the lines that can be found in both files. I do this using the following AWK script:

BEGIN { IGNORECASE = 1 }  # ignoring the case
       NR==FNR { a[$1]; next }   # hash csv to a hash
       {
           for(i in a) {          # each entry in a
               if($0 ~ i) {      # check against every record of ttl
                   print >> "testrunawk1.txt"        # if match, output matched ttl record
                   next          # skip to next ttl record
               }
            }
       }

现在,当我运行AWK脚本时,在所有这些行上都收到以下错误:

Right now I get the following error on all these lines when I run the AWK script:

Fatal: unmatched ( or \(: //resource/text_(moretext/

非常感谢您的帮助:)

推荐答案

使用带有-E选项的sed,您可以执行以下操作:

Using sed with -E option you could do:

sed -E 's/\([^)]+$/\0)/' file

使用Notepad ++,您可以执行此操作,只是在字符类中最好使用\r包括换行符.

With Notepad++ you can do the same with this difference that you should include newline character preferably with \r in character class.

这篇关于Notepad ++查找所有带有开括号但没有小括号的行,并为AWK脚本错误添加更小括号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆