如何使用“less”搜索带有小数点的值的文件?

not*_*nce 7 less regular-expression

所以我少了我的文件:

less myFile.log
Run Code Online (Sandbox Code Playgroud)

然后我尝试搜索一个值:

/70.5
Run Code Online (Sandbox Code Playgroud)

从那以后,我学会了较少使用正则表达式,所以.是通配符。我试图逃避它但没有成功。

ste*_*ver 40

您可以通过在输入模式之前点击Ctrl+R来关闭正则表达式模式:

          ^R     Don't interpret regular expression metacharacters; that is,
                 do a simple textual comparison.
Run Code Online (Sandbox Code Playgroud)


Ste*_*itt 30

/70\.5
Run Code Online (Sandbox Code Playgroud)

会做的伎俩(内less)。

  • 或者:`/70[.]5`。 (6认同)

sud*_*dus 5

两个搜索表达式中的数字less

/\.*[0-9]+\.*     # for numbers

/[0-9]*\.[0-9]+   # for numbers with a decimal part
Run Code Online (Sandbox Code Playgroud)

用于搜索数字的正则表达式(带或不带小数)

此正则表达式适用于less使用相同正则表达式语法的其他情况。

\.*[0-9]+\.*
Run Code Online (Sandbox Code Playgroud)

您使用 启动搜索引擎/,因此如果您想查找十进制数字,但避免在句子之间使用点(如 file.txt)或句点的文本,我认为以下字符串相当不错,

/\.*[0-9]+\.*

测试文件

There are several ways to use a dot. Here are some examples:

- 'Period' finishing a sentence
- Short for current directory or 'source' command in linux shells
- Separator between the name and extension of a file
- Separator in between the integer part and decimal part of a number
- Separator in special numerical or litteral strings (for example IP adress)

The following regex expression is rather simple and can identify
- numbers
- numerial strings

\.*[0-9]+\.*

.bashrc
hello-0
170.5
text.txt
170
170.
.551
asdf 170.5 qwerty
192.168.1.1
file.000
file.001
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

正则表达式搜索带小数部分的数字

此正则表达式适用于less使用相同正则表达式语法的其他情况。

[0-9]*\.[0-9]+
Run Code Online (Sandbox Code Playgroud)

对应的搜索命令是

/[0-9]*\.[0-9]+

它还会查找数字字符串(例如 IP 地址),通常是点后的数字(包括点前的数字,如果有的话)。