grep内容后模式 [英] grep for contents AFTER pattern
本文介绍了grep内容后模式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
土豆:1234
苹果:5678
土豆:5432
葡萄:4567
香蕉:5432
寿司:56789
我想grep所有以马铃薯:
开头的行,但只填写 Potato
后面的数字。所以在上面的例子中,输出结果是:
1234
5432
$ c $ <$> p $ p> grep'potato:'file.txt | sed's /^.*://'
或
grep'potato:'file.txt | cut -d\ -f2
或
grep'potato:'file.txt | awk'{print $ 2}'
或
grep'potato:'file.txt | perl -e'(<>){s/^.*:∥; print}'
或
awk'{if(/ potato:/)print $ 2}'< file.txt
或
perl -e'(<>){/ potato:/&& s /^.*://&&打印}'< file.txt
Given a file, example:
potato: 1234
apple: 5678
potato: 5432
grape: 4567
banana: 5432
sushi: 56789
I'd like to grep for all lines that start with potato:
but only pipe the numbers that follow Potato
. So in the above example, the output would be:
1234
5432
How can I do that?
解决方案
grep 'potato:' file.txt | sed 's/^.*: //'
or
grep 'potato:' file.txt | cut -d\ -f2
or
grep 'potato:' file.txt | awk '{print $2}'
or
grep 'potato:' file.txt | perl -e 'for(<>){s/^.*: //;print}'
or
awk '{if(/potato:/) print $2}' < file.txt
or
perl -e 'for(<>){/potato:/ && s/^.*: // && print}' < file.txt
这篇关于grep内容后模式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文