简体   繁体   English

在AWK生成的命令字符串中嵌入引号?

[英]Embedding quotation marks in command string generated by AWK?

I need to match all instances of strings in one file, with a master list in another. 我需要将一个文件中所有字符串的实例与另一个文件中的主列表匹配。 However, if my string is abc I want only that, not abcdef , abc1234 and so on. 但是,如果我的字符串是abc ,那么我只想要那个,而不是abcdefabc1234等等。

So, a word boundary for the regex? 那么,正则表达式的字边界是什么? Right now, I'm using a simple awk one liner: 现在,我正在使用一个简单的awk one班轮:

cat results_file| sort -k 1| awk -F" " '{ print $1" /home/owner/file_2_search"}'|
xargs -L 1 /bin/grep -i

However, to force a word boundary, I'd need to grep string\\b and the quotes (single or double) seem to be required. 但是,要强制使用单词边界,我需要grep string\\b并且似乎需要引号(单引号或双引号)。

In awk, \\b is a special character, you need \\\\b ... And the quoted quotes ... (arg) ... Or am I missing something and overdoing this? 在awk中, \\b是一个特殊字符,您需要\\\\b ...引号引起来...(arg)...还是我错过了某些内容并过度使用了?

This is a Linux box, so presumably gawk. 这是一个Linux机器,大概是gawk。 I have gone over quoting rules for awk, and realize this has got to be simple (and not complex ... but), but am not seeing it. 我已经遍历了awk的引用规则,并且意识到这必须很简单(而不是复杂...但是),但是我没有看到它。

Had meant to post as an answer, not a comment. 本来打算将其发布为答案,而不是评论。 Will try to pose a more readable question, but confess to having second thoughts about doing this as a one-liner in the first place -- may be best to follow an alternate method. 将尝试提出一个更具可读性的问题,但首先要承认对以单线方式进行此操作具有第二种想法-最好采用替代方法。 Appreciate the willingness to help. 赞赏愿意提供帮助。 --Joe --Joe

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM