How do you do a case insensitive search using a pattern modifier using less?

UnixSearchCase InsensitiveLess Unix

Unix Problem Overview


It seems like the only way to do this is to pass the -i parameter in when you initially run less. Does anyone know of some secret hack to make something like this work

/something to search for/i

Unix Solutions


Solution 1 - Unix

You can also type command -I while less is running. It toggles case sensitivity for searches.

Solution 2 - Unix

You can also set the environment variable LESS

I use LESS=-Ri, so that I can pump colorized output from grep into it, and maintain the ANSI colour sequences.

Another little used feature of less that I found is starting it with +F as an argument (or hitting SHIFT+F while in less). This causes it to follow the file you've opened, in the same way that tail -f <file> will. Very handy if you're watching log files from an application, and are likely to want to page back up (if it's generating 100's of lines of logging every second, for instance).

Solution 3 - Unix

Add-on to what @Juha said: Actually -i turns on Case-insensitive with SmartCasing, i.e if your search contains an uppercase letter, then the search will be case-sensitive, otherwise, it will be case-insensitive. Think of it as :set smartcase in Vim.

E.g.: with -i, a search for 'log' in 'Log,..' will match, whereas 'Log' in 'log,..' will not match.

Solution 4 - Unix

It appears that you can summon this feature on a per search basis like so:

less prompt> /search string/-i

This option is in less's interactive help which you access via h:

less prompt> h
...
  -i  ........  --ignore-case
                  Ignore case in searches that do not contain uppercase.
  -I  ........  --IGNORE-CASE
                  Ignore case in all searches.
...

I've not extensively checked but the help in less version 487 on MacOS as well as other Linux distros lists this option as being available.

On MacOS you can also install a newer version of less via brew:

$ brew install less
$ less --version
less 530 (POSIX regular expressions)
Copyright (C) 1984-2017  Mark Nudelman
References

Solution 5 - Unix

When using -i flag, be sure to enter the search string completely in lower case, because if any letter is upper case, then its an exact match.

See also: the -I (capital i) flag of less(1) to change this behavior.

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
Questionmk.View Question on Stackoverflow
Solution 1 - UnixJuha SyrjäläView Answer on Stackoverflow
Solution 2 - UnixsanmiguelView Answer on Stackoverflow
Solution 3 - UnixAntony ThomasView Answer on Stackoverflow
Solution 4 - UnixslmView Answer on Stackoverflow
Solution 5 - UnixjoeView Answer on Stackoverflow