使用Grep在单词内过滤特定字母 [英] Filter a specific letter within a word using Grep
本文介绍了使用Grep在单词内过滤特定字母的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我一直在试图找到一种方法来使用正则表达式来筛选单词中的特定字母。例如,过滤单词拉丁语中的字母a。仅使用类似以下内容过滤一封信函就很简单:
I've been trying to find a way to filter a specific letter within a word using a regular expression. For exemple, filtering the letter "a" in the word "latin". Filtering only a letter would be simple using something like :
grep "\ba\b"
但我无法找到一种方法只能在某个字中获得a。
but I can't find a way to get the "a" only in a certain word.
感谢您的帮助!
Thanks for your help!
推荐答案
p>
You can pipe to another grep, like this:
grep "\ba\b" /path/to/input/file | grep -o "a"
管道的后半部分使用 o
标志只输出匹配的部分。或者 grep -oa
应该返回所有a。
The latter part of the pipe uses the o
flag which only outputs the matched part. Alternatively grep -o "a"
should return all a's.
这篇关于使用Grep在单词内过滤特定字母的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文