Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的输入:
1:FAILED + *1 0 (8328832,AR,UNDECLARED)
这是我所期望的:
8328832,AR,UNDECLARED
我正在尝试找到一个通用正则表达式,它允许取出两个括号之间的任何内容。
我的尝试是
grep -o '\[(.*?)\]' test.txt > output.txt
但它不匹配任何东西。
仍在使用grep和regex
grep -oP '\(\K[^\)]+' file
\K表示使用环视正则表达式高级功能。更准确地说,这是一个积极的后视断言,你也可以这样做:
\K
grep -oP '(?<=\()[^\)]+' file
如果您缺少该-P选项,则可以使用perl执行此操作:
-P
perl -lne '/\(\K[^\)]+/ and print $&' file
使用awk的另一种更简单的方法
awk -F'[()]' '{print $2}' file