如何打印字正则表达式后,但没有类似的词吗? [英] How do i print word after regex but not a similar word?

查看:114
本文介绍了如何打印字正则表达式后,但没有类似的词吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想一个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屋!

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