[英]How to find a specific pattern in bash
I want to find a pattern '@s241'
in a file, which is easy using: 我想在文件中找到模式
'@s241'
,使用起来很容易:
grep '@s241' file
or 要么
awk '/@s241/' file
But the problem is that the file contains patterns such as @s2470 or @s2478 但是问题在于该文件包含诸如@ s2470或@ s2478之类的模式
How could I specify the exact pattern is @s247 with no extension? 我如何指定确切的模式是@ s247,没有扩展名?
Thanks 谢谢
Use -w
in grep. 在grep中使用
-w
。
grep -w '@s247' file
or 要么
grep -P '(^|\s)@s247(\s|$)' file
or 要么
awk '/(^| )@s247( |$)/'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.