[英]shell grep, regex to find a specific occurence
using grep I want to find all the strings like this: .some_char
. 使用grep我想找到这样的所有字符串:
.some_char
。 I have a text like this: 我有这样的文字:
Lorem ipsum dolor sit amet**,c**onsectetur adipisici elit**,s**ed eiusmod tempor incidunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquid ex ea commodi consequat
i want to find ",c" ",s" . 我想找到“,c”“,s”。 So i need a regex.
所以我需要一个正则表达式。 Can you help me?
你能帮助我吗?
SOLUTION: 解:
cat file.txt | grep -o -E ",[a-zA-Z0-9]"
The regex should be 正则表达式应该是
",."
Furthermore you need to set some additional flag in grep
(-o to print only the matching part) 此外,您需要在
grep
设置一些额外的标志(-o只打印匹配的部分)
The full command is thus: 完整的命令是:
grep -r ",." -o
The question is a bit unclear. 问题有点不清楚。 If by some_char you mean alphabetic characters, you could do
如果some_char你的意思是字母字符,你可以这样做
grep -o ',[A-Za-z]'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.