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

0

2 Answers 2

4

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

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

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .