Not so good news
Redirecting the output of an interactive screen like that will usually result in a file that contains escape sequences ... These are control character sequences that you don't see and used for e.g. resetting/clearing the terminal screen or changing the position of the cursor ... etc.
Running the file
command on the saved file should output something like this:
$ file file.txt
file.txt: ASCII text, with escape sequences
This kind of files/output can not be easily parsed/processed so cannot e.g. be easily separated to records/blocks so you get only the last block ... Sometimes it cannot even be displayed correctly in the terminal with e.g. cat file.txt
as the escape sequences will alter the terminal's display.
Your best bet is to use the -P
or -L
switches(to produce an output suitable to be redirected into a file) as described in man netdiscover
... But, then you will lose the repeated screen headers and only one header is printed at the top of the file ... So, you can't e.g. process the text into blocks based on the header ... Sure, you can then e.g. combine the output of both head
to print the first N lines and tail
to print the last N lines like for examble:
{ head -n 3 file.txt; tail -n 12 file.txt; }
But, there will be no standard for e.g. how many lines to tail
and not loose any important output.
So good news
My other answer in this post: Warn when new WiFi devices on LAN network has a bash script(The terminal display version) that will do what you want and without even the need for sudo
... It will both print in the terminal screen and to a log file ... It is also easily customizable if you know your bash
.