1

inside less i can type &/!DEBUG|INFO to exclude DEBUG and INFO patterns from a big log file

How can i send this from an alias, bash script or the command line

> # start less at last ERROR
> less +?ERROR foo.log  # works from cmd line (takes me to last line matching ERROR )

# For greping in less (the & is the problem of course)
> less +&INFO foo.log  # won't work 
> less +\&INFO foo.log  # won't work
> less +'&'INFO foo.log  # won't work

The actual patterns I'm excluding are longer and several p1|p2|p3

Not looking for pipe through grep -v, want to be able to use less +F etc

3

less $'+&INFO\r' file or less $'+&INFO\n' file

See the bash manual for the $'...' syntax.

| improve this answer | |
0

Great, using the $'+&INFO' strategy seems like the best way to do it.

For completeness I'll add the option --use-backslash, but it won't allow \n or \r (which helps you to not have to hit enter once in less.

less +G --use-backslash +\&\!DEBUG\|INFO foo.log
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.