如何打印字正则表达式后,但没有类似的词吗? [英] How do i print word after regex but not a similar word?
问题描述
我想一个awk或sed的命令正则表达式后打印字。
I want an awk or sed command to print the word after regexp.
我想一个字,但不是词,类似于后找到的单词。
I want to find the WORD after a WORD but not the WORD that looks similar.
文件看起来是这样的:
somethingsomething
X-Windows-Icon=xournal
somethingsomething
Icon=xournal
somethingsomething
somethingsomething
我想从一个说图标= Xournal之类Xournal之类。这是多远我来了,直到现在。我已经试过了AWK字符串太多,但它也是不成功的。
I want "xournal" from the one that say "Icon=xournal". This is how far i have come until now. I have tried an AWK string too but it was also unsuccessful.
cat "${file}" | grep 'Icon=' | sed 's/.*Icon=//' >> /tmp/text.txt
但我得到这么两种文本文件中给出了两个Xournal之类,我不想要的。
But i get both so the text file gives two xournal which i don't want.
推荐答案
使用 ^
在该行的开头以固定的模式。你甚至可以做到直接在sed就grepping:
Use ^
to anchor the pattern at the beginning of the line. And you can even do the grepping directly within sed:
sed -n '/^Icon=/ { s/.*=//; p; }' "$file" >> /tmp/text.txt
您也可以使用awk中,我认为读好一点。使用 =
作为字段分隔符,如果场1 图标
然后打印领域2:
You could also use awk, which I think reads a little better. Using =
as the field separator, if field 1 is Icon
then print field 2:
awk -F= '$1=="Icon" {print $2}' "$file" >> /tmp/text.txt
这篇关于如何打印字正则表达式后,但没有类似的词吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!