使用AWK的包含正斜杠的搜索模式 [英] Search pattern containing forward slash using AWK
问题描述
在AWK中,是否有一种方法可以匹配包含正斜杠/
的模式而没有实际转义呢?
In AWK, is there a way to match pattern containing forward slash /
without actually escaping it?
awk '$1~/pattern/' file
只要模式中没有任何/
,上述命令就可以正常工作.
The above command works fine as long as there isn't any /
in the pattern.
我正在寻找与 sed 中可用的内容类似的内容,以便在搜索中使用不同的分隔符并替换语法.
I am looking for something similar to what's available in sed for using different separators in search and replace syntax.
推荐答案
是的,你可以
awk '$0~v' v="patt/ern"
说明
NB:是从评论中提取的,所以也要对其进行投票!
Explanation
N.B.: extracted from comments, so upvote them too!
在awk
动态正则表达式和正则表达式常量中并不完全相同. OP问题中的示例是 regex常量,您将其变成了 dynamic regex (请参见.
In awk
dynamic regex and regex constant are not exactly same. The example in OP's question was regex constant you turned it into dynamic regex (see. Using Dynamic Regexps).
这篇关于使用AWK的包含正斜杠的搜索模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!