I would like to paginate a file with follow, i.e. $less +F and also colorize the output on the screen.

I want to use less because I can leave the follow mode, browse the file and then re-enter the follow mode.

I want something like that:

tail -f ./StdOutErr.0 | awk -v RS='\r\n' '
/STDOUT/ {print $0}
/STDERR/ {print "\033[38;5;202m" $0 "\033[39m"}
' | less -R +F

But it is not working, i just get an empty screen. Ideas someone?

  • 1
    sounds like your file doesn't have lines ending \r\n. Try cat -vet on it and check you see ^M$ at the end of each line. – meuh May 9 '16 at 14:40
  • 1
    You might try using printf instead of print and specifying the escape character in a more portable fashion. – Wildcard May 9 '16 at 16:22
  • My file is a regular file with lines ending. I can see a "...scanning..." in the terminal but still nothing else. – njames May 10 '16 at 9:13
  • First check, that this command works without less. – citrin Sep 1 '16 at 21:28
  • If the file doesn't contain lines with STDOUT and STDERR (literally those strings), awk will print nothing. – Thomas Dickey Jan 21 '17 at 1:44

Your Answer

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

Browse other questions tagged or ask your own question.