Read logs using less command in vi editor?

Joined
Apr 16, 2023
Messages
149
Reaction score
16
Credits
1,460
Code:
2023-08-07 09:20:35 0123456789 INFO  CustomerLogoutResource:95 - Entering logout api.
2023-08-07 09:20:35 0123456789 ERROR AppExceptionMapper:87 - Exception has been thrown by container
2023-08-07 09:20:35 0123456789 ERROR AppExceptionMapper:555 - Unchecked Exception
java.lang.NullPointerException
    at NullPointerExceptionExample.printLength(NullPointerExceptionExample.java:3)
    at NullPointerExceptionExample.main(NullPointerExceptionExample.java:8)

The logs look like this.
[LIST]
[*]There is not phone number=0123456789 in every line.
[/LIST]
So,
egrep -i "0123456789" application.log | less

Will skip the lines that don't contain that java null pointer exception which is extremely important.
egrep -i "0123456789| 'java'| 'at' " application.log | less

could work but it's too hacky and not ideal solution imo.
Is there anything that is better.
Problem statement: Old vi editor(although it says vim) and no full searched keyword highlighting feature which is terrible for eyes and stress.
 


If you wish to highlight all the searched words in a doc, you can set that feature with the config in the file:
Code:
:set hlsearch
If you want it to be set for all vim's operations, set it in the .vimrc where you can write it, as above but without the colon. I think that's what you are after, but if not, let's know.
 
set command not found.
I guess then it's not modern vim mode that you are running, since the command in post #2 is vim standard. If set within a file, it will highlight selected text as long as that file is open.

Speculatively, perhaps your vim, (if the text editor you are running is indeed vim), is running as old vi. That's a guess. There is a setting that you can place in the .vimrc file which will allow vim to behave as modern vim with its features over and above the old vi. You would need to place the following in the .vimrc file:
Code:
set nocompatible
I guess if that doesn't work, I'd update vim.
 
sudo su -

Give your password, get privileges. ;)
 
@Brief-Wishbone9091 is running vi, which is currently facilitated by running vim-tiny, which is an extremely cut-down version of Vim. Ran in compatible mode, which makes it behave exactly like classic vi, without any of vim’s many extensions. Vim-tiny only has a tiny subset of vim’s features compiled into it. I haven’t ran vim-tiny in such a long time, I can’t actually remember what the differences between vim-tiny and the full-fat version of vim are.

But as the version of Vim being used by the OP is one of the minimal ones, setting nocompatible will only enable the few vim extensions that are compiled into the minimal version. So it will still be missing a lot of features. But it will probably make things easier than running vim in compatible mode.
 
@JasKinasis wrote:
running vim-tiny, which is an extremely cut-down version of Vim.
Thanks for that JasKinasis. It does explain the difficulty.

@Brief-Wishbone9091 wrote:
egrep -i "0123456789| 'java'| 'at' " application.log | less
could work but it's too hacky and not ideal solution imo.

That egrep command in the quoted form will not work in the form presented. The single quotes need to be removed for it to run as intended. If the less pager is used, the terms being searched for will not appear in color ... that is, if the terminal is color-enabled. If the command is used without the less pager, egrep will normally highlight the selected terms by default in red on modern consoles or terminals.

It may not be appealing, but as I understand the situation, you have access to the journal output, so, if the journal output is written to a file, say by redirection (>), then the user is able to search it with egrep to highlight terms, if that's the aim. It's perhaps not the most economical way of dealing with the situation, nor the least onerous, but if the objective is to get the journal output, seek out relevant parts and then be informed about what it's reporting and what problems there may be, then the extra effort may be worth it. YMMV.
 
Last edited:

Staff online

Members online


Latest posts

Top