使用 grep 搜索包含点的字符串

编程入门 行业动态 更新时间:2024-10-25 10:26:26
本文介绍了使用 grep 搜索包含点的字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用命令搜索字符串 0.49(带点)

I am trying to search for a string 0.49 (with dot) using the command

grep -r "0.49" *

但是发生的事情是我也得到了不需要的结果,其中包含诸如 0449、0949 等字符串.事情是 linux 将 dot(.) 视为任何字符并带出所有结果.但我只想得到0.49"的结果.

But what happening is that I am also getting unwanted results which contains the string such as 0449, 0949 etc,. The thing is linux considering dot(.) as any character and bringing out all the results. But I want to get the result only for "0.49".

推荐答案

grep 使用正则表达式;. 在正则表达式中表示任何字符".如果您需要文字字符串,请使用 grep -F、fgrep,或将 . 转义为 ..

grep uses regexes; . means "any character" in a regex. If you want a literal string, use grep -F, fgrep, or escape the . to ..

不要忘记用双引号将字符串括起来.否则你应该使用 \.

Don't forget to wrap your string in double quotes. Or else you should use \.

因此,您的命令需要是:

So, your command would need to be:

grep -r "0.49" *

grep -r 0\.49 *

grep -Fr 0.49 *

更多推荐

使用 grep 搜索包含点的字符串

本文发布于:2023-08-01 08:51:27,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1267004.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:字符串   grep

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!