So I less my file:
less myFile.log
Then I try to search for a value:
/70.5
I've since learned less uses regex, so .
is a wildcard. I've tried to escape it with no success.
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. It only takes a minute to sign up.
Sign up to join this communitySo I less my file:
less myFile.log
Then I try to search for a value:
/70.5
I've since learned less uses regex, so .
is a wildcard. I've tried to escape it with no success.
You can turn off regex mode by hitting Ctrl+R before typing the pattern:
^R Don't interpret regular expression metacharacters; that is, do a simple textual comparison.
more
supports it (although other pagers may provide something equivalent)
Jan 15, 2019 at 16:54
fgrep "something" file(s)
: will look for the exact string "something" in the file(s), doing a car by car comparison and not as a regexp)
Jan 16, 2019 at 12:50
/70\.5
will do the trick (inside less
).
less
/\.*[0-9]+\.* # for numbers
/[0-9]*\.[0-9]+ # for numbers with a decimal part
This regex works in less
but also in other cases where the same regex syntax is used.
\.*[0-9]+\.*
You start the search engine with /
, so if you want to find decimal numbers, but avoid text with dots (like file.txt) or periods between sentences, I think the following string is rather good,
/\.*[0-9]+\.*
Test file
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
This regex works in less
but also in other cases where the same regex syntax is used.
[0-9]*\.[0-9]+
The corresponding search command is
/[0-9]*\.[0-9]+
It will also find numerical strings (for example IP address), in general digits after a dot (including digits before the dot, if any).
[0-9]*\.[0-9]*
matches on a single .
. *
matches on zero or more.
Jan 15, 2019 at 17:23
\.*[0-9]+\.*
in the current version of the answer. Your second string will exclude some of dots (which may be good or bad depending on what the user wants to see).
70.5
? Maybe there's a misunderstanding of "escape"?