I have an interactive shell-like program, that outputs a lot of irrelevant error messages, that confuse our customers. Each of these error messages are full-line messages starting with "%".
So the easy way to get rid of them would be something like this:
command | grep -v "^%[^\n]*$"
With command being the shell-like program.
But the problem with that is, that it only outputs anything to the user, after it received a newline. So when the user types anything into the program, there is no feedback of what they typed, until they press enter.
Is there a way to do something like this non-line based? I thought of programming a little something in Python, but on that machine (very slow embedded device) starting Python takes multiple seconds, which is not acceptable.
To add more clarity, I'll explain a bit more:
The program that this is about is not under my control, so I can't change what it does (otherwise I'd just get the program to stop outputting these error messages). The program is used to view or change settings on the device in a Cisco-Shell style. A typical user interaction might look like this:
linux-shell# command
% Error: some meaningless error
fake-cisco-shell# show status
Status report: status ok
% Error: some meaningless error
fake-cisco-shell# exit
linux-shell#
Every time the user presses a key, the letter that they typed appears on the screen as they type it, so that they can see what they typed, similar as on a regular bash shell.
Now if I do something like this:
command | grep -v "%[^\n]*\n"
Then the letters typed (and also the input prompt) will only show up after the user pressed enter and thus ended the line, because grep caches lines. So something like this ("<" = inputs from the user, ">" outputs from the program):
> fake-cisco-shell#
< s
> s
< h
> h
< o
> o
< w
> w
< \n
> \n
> Result of the command\n
> fake-cisco-shell#
Now looks like this:
>(no output)
< s
< h
< o
< w
< \n
> fake-cisco-shell# show\n
> Result of the command\n
So as you see, it does not output each character on it's own when the program sends it, but instead waits for the next \n and only then grep forwards the content.
I am not sure grep can actually do what I want, so I am also open to suggestions to other programs.
stderr
instead ofstdout
?cat | command | grep -v ...
. If you mean something else, can you please clarify what you mean by "it only outputs anything to the user, after it received a newline"