使用grep来搜索一个有点的字符串 [英] Using grep to search for a string that has a dot in it

查看:191
本文介绍了使用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 使用regexes; 表示正则表达式中的任何字符。如果你想要一个字符串,可以使用 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 \..

这篇关于使用grep来搜索一个有点的字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆