2

It's very convenient to monitor logs using less command - you see what is going with your system as it happening. The bad thing is that my logs are optimized for grep tool: each atomic action is always printed in a single line (I can easily lookup for actions performed by certain user then).

Still, actions contain incoming messages, which are more user-friendly if being printed multiline. If I want to filter log "offline", it's easy:

cat ./log/system.log | tail -50 | tr '\\n' '\n'

Can I do those replacements "online"? What I mean is that replacements are done as new text being appended to log and shown to the screen like less + G.

1
  • Note that tr '\\n' '\n' would transliterate both backslash and n characters to a newline one with haft tr implementations, and backslashes only in the other half. That is not substituting \n with a newline character. Commented Mar 26, 2015 at 9:43

2 Answers 2

2

You can if you drop the redundant cat command.

tail -f ./log/system.log | tr '\\n' '\n'

or putting a filter in there:

tail -f ./log/system.log | grep [whatever] | tr '\\n' '\n'
1
  • 1
    grep usually needs the --line-buffered parameter when taking a stream as input.
    – wullxz
    Commented Feb 1, 2018 at 14:21
2

Have you tried replacing tail -50 with tail -f ?

tail -fn50 ./log/system.log | sed 's/\\n/\
/g'
1
  • tail -F rather than -f, so that the named file is watched. Otherwise things will grind to a halt if the file is archived (i.e. logrotate etc.). Commented Feb 20 at 21:16

You must log in to answer this question.

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