2

I'm trying to combine less +F with a &pattern, but can't get it to work like I want:

less +F'&foo|bar' file.log

It seems to ignore my pattern.

  • If your looking for a regex, why not use tail -f file.log | grep '&foo|bar' – ryekayo Dec 2 '15 at 19:11
  • 1
    Because I want to be able to switch between tailing and browsing the file. – nilfric Dec 2 '15 at 19:14
  • While I'm not sure what +F would do (what flavour of less is this?), the versions of less I have expect any search pattern via the -p pattern flag. – thrig Dec 2 '15 at 19:35
  • @thrig The +F enables scrolling in less.. – ryekayo Dec 2 '15 at 20:23
  • @thrig What ryekayo said and while in less, you can activate scrolling with Shift-F and then use ^C to return to normal mode. – nilfric Dec 2 '15 at 21:42
1

You need to run the filter command before the follow command, otherwise the filter command is never applied (pressing Ctrl+C to get out of follow mode cancels any pending input, including fake input injected via the command line).

So in the + argument, you need to pass the &foo|bar command first, then the F command. To terminate the & command, you need a newline.

less +$'&foo|bar\nF' file.log

(Assuming your shell is ksh, bash or zsh, where $'\n' expands to a newline.)

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.