How do I search a file using “less” for a value with a decimal point?












4















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.










share|improve this question




















  • 11





    How did you "try to escape it with no success" without using a backslash?

    – Xen2050
    2 days ago
















4















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.










share|improve this question




















  • 11





    How did you "try to escape it with no success" without using a backslash?

    – Xen2050
    2 days ago














4












4








4


1






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.










share|improve this question
















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.







regular-expression less






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago









Rui F Ribeiro

39.5k1479133




39.5k1479133










asked 2 days ago









xeon48xeon48

1314




1314








  • 11





    How did you "try to escape it with no success" without using a backslash?

    – Xen2050
    2 days ago














  • 11





    How did you "try to escape it with no success" without using a backslash?

    – Xen2050
    2 days ago








11




11





How did you "try to escape it with no success" without using a backslash?

– Xen2050
2 days ago





How did you "try to escape it with no success" without using a backslash?

– Xen2050
2 days ago










3 Answers
3






active

oldest

votes


















28














/70.5


will do the trick (inside less).






share|improve this answer



















  • 5





    Alternatively: /70[.]5.

    – jamesdlin
    2 days ago



















38














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.






share|improve this answer
























  • Amazing trick, thanks for this! Is it specific to less?

    – xeon48
    2 days ago











  • @xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

    – steeldriver
    2 days ago











  • Thanks steel, I'll play around with it when I get a chance :)

    – xeon48
    2 days ago











  • @xeon48 : it seems specific to less, but there are some alternatives (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)

    – Olivier Dulac
    yesterday



















3














Two search expressions for numbers in less



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

/[0-9]*.[0-9]+ # for numbers with a decimal part


Regex to search for numbers (with or without a decimal)



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


enter image description here



Regex to search 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]*.[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).






share|improve this answer


























  • Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

    – xeon48
    2 days ago






  • 1





    [0-9]*.[0-9]* matches on a single .. * matches on zero or more.

    – Stéphane Chazelas
    2 days ago











  • @StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

    – sudodus
    2 days ago






  • 1





    [0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

    – Stephen Kitt
    2 days ago











  • @StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

    – sudodus
    2 days ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494637%2fhow-do-i-search-a-file-using-less-for-a-value-with-a-decimal-point%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























3 Answers
3






active

oldest

votes








3 Answers
3






active

oldest

votes









active

oldest

votes






active

oldest

votes









28














/70.5


will do the trick (inside less).






share|improve this answer



















  • 5





    Alternatively: /70[.]5.

    – jamesdlin
    2 days ago
















28














/70.5


will do the trick (inside less).






share|improve this answer



















  • 5





    Alternatively: /70[.]5.

    – jamesdlin
    2 days ago














28












28








28







/70.5


will do the trick (inside less).






share|improve this answer













/70.5


will do the trick (inside less).







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









Stephen KittStephen Kitt

167k24376454




167k24376454








  • 5





    Alternatively: /70[.]5.

    – jamesdlin
    2 days ago














  • 5





    Alternatively: /70[.]5.

    – jamesdlin
    2 days ago








5




5





Alternatively: /70[.]5.

– jamesdlin
2 days ago





Alternatively: /70[.]5.

– jamesdlin
2 days ago













38














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.






share|improve this answer
























  • Amazing trick, thanks for this! Is it specific to less?

    – xeon48
    2 days ago











  • @xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

    – steeldriver
    2 days ago











  • Thanks steel, I'll play around with it when I get a chance :)

    – xeon48
    2 days ago











  • @xeon48 : it seems specific to less, but there are some alternatives (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)

    – Olivier Dulac
    yesterday
















38














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.






share|improve this answer
























  • Amazing trick, thanks for this! Is it specific to less?

    – xeon48
    2 days ago











  • @xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

    – steeldriver
    2 days ago











  • Thanks steel, I'll play around with it when I get a chance :)

    – xeon48
    2 days ago











  • @xeon48 : it seems specific to less, but there are some alternatives (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)

    – Olivier Dulac
    yesterday














38












38








38







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.






share|improve this answer













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.







share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









steeldriversteeldriver

35.5k35286




35.5k35286













  • Amazing trick, thanks for this! Is it specific to less?

    – xeon48
    2 days ago











  • @xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

    – steeldriver
    2 days ago











  • Thanks steel, I'll play around with it when I get a chance :)

    – xeon48
    2 days ago











  • @xeon48 : it seems specific to less, but there are some alternatives (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)

    – Olivier Dulac
    yesterday



















  • Amazing trick, thanks for this! Is it specific to less?

    – xeon48
    2 days ago











  • @xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

    – steeldriver
    2 days ago











  • Thanks steel, I'll play around with it when I get a chance :)

    – xeon48
    2 days ago











  • @xeon48 : it seems specific to less, but there are some alternatives (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)

    – Olivier Dulac
    yesterday

















Amazing trick, thanks for this! Is it specific to less?

– xeon48
2 days ago





Amazing trick, thanks for this! Is it specific to less?

– xeon48
2 days ago













@xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

– steeldriver
2 days ago





@xeon48 likely it is - at least, I don't think more supports it (although other pagers may provide something equivalent)

– steeldriver
2 days ago













Thanks steel, I'll play around with it when I get a chance :)

– xeon48
2 days ago





Thanks steel, I'll play around with it when I get a chance :)

– xeon48
2 days ago













@xeon48 : it seems specific to less, but there are some alternatives (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)

– Olivier Dulac
yesterday





@xeon48 : it seems specific to less, but there are some alternatives (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)

– Olivier Dulac
yesterday











3














Two search expressions for numbers in less



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

/[0-9]*.[0-9]+ # for numbers with a decimal part


Regex to search for numbers (with or without a decimal)



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


enter image description here



Regex to search 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]*.[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).






share|improve this answer


























  • Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

    – xeon48
    2 days ago






  • 1





    [0-9]*.[0-9]* matches on a single .. * matches on zero or more.

    – Stéphane Chazelas
    2 days ago











  • @StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

    – sudodus
    2 days ago






  • 1





    [0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

    – Stephen Kitt
    2 days ago











  • @StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

    – sudodus
    2 days ago


















3














Two search expressions for numbers in less



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

/[0-9]*.[0-9]+ # for numbers with a decimal part


Regex to search for numbers (with or without a decimal)



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


enter image description here



Regex to search 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]*.[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).






share|improve this answer


























  • Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

    – xeon48
    2 days ago






  • 1





    [0-9]*.[0-9]* matches on a single .. * matches on zero or more.

    – Stéphane Chazelas
    2 days ago











  • @StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

    – sudodus
    2 days ago






  • 1





    [0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

    – Stephen Kitt
    2 days ago











  • @StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

    – sudodus
    2 days ago
















3












3








3







Two search expressions for numbers in less



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

/[0-9]*.[0-9]+ # for numbers with a decimal part


Regex to search for numbers (with or without a decimal)



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


enter image description here



Regex to search 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]*.[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).






share|improve this answer















Two search expressions for numbers in less



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

/[0-9]*.[0-9]+ # for numbers with a decimal part


Regex to search for numbers (with or without a decimal)



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


enter image description here



Regex to search 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]*.[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).







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago

























answered 2 days ago









sudodussudodus

1,30616




1,30616













  • Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

    – xeon48
    2 days ago






  • 1





    [0-9]*.[0-9]* matches on a single .. * matches on zero or more.

    – Stéphane Chazelas
    2 days ago











  • @StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

    – sudodus
    2 days ago






  • 1





    [0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

    – Stephen Kitt
    2 days ago











  • @StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

    – sudodus
    2 days ago





















  • Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

    – xeon48
    2 days ago






  • 1





    [0-9]*.[0-9]* matches on a single .. * matches on zero or more.

    – Stéphane Chazelas
    2 days ago











  • @StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

    – sudodus
    2 days ago






  • 1





    [0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

    – Stephen Kitt
    2 days ago











  • @StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

    – sudodus
    2 days ago



















Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

– xeon48
2 days ago





Thanks for this, it will come in useful. Though the lesson learned here is brush up on my regex :)

– xeon48
2 days ago




1




1





[0-9]*.[0-9]* matches on a single .. * matches on zero or more.

– Stéphane Chazelas
2 days ago





[0-9]*.[0-9]* matches on a single .. * matches on zero or more.

– Stéphane Chazelas
2 days ago













@StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

– sudodus
2 days ago





@StéphaneChazelas, Yes, I know, and I am busy trying to get around that without getting a complicated expression ...

– sudodus
2 days ago




1




1





[0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

– Stephen Kitt
2 days ago





[0-9]+(.[0-9]*)? or even [0-9]+(.[0-9]+)? maybe?

– Stephen Kitt
2 days ago













@StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

– sudodus
2 days ago







@StephenKitt, I think your first expression finds the same 'candidates' as my first string .*[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).

– sudodus
2 days ago




















draft saved

draft discarded




















































Thanks for contributing an answer to Unix & Linux Stack Exchange!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f494637%2fhow-do-i-search-a-file-using-less-for-a-value-with-a-decimal-point%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

"Incorrect syntax near the keyword 'ON'. (on update cascade, on delete cascade,)

Alcedinidae

RAC Tourist Trophy