Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Possible Duplicate:
Removing control chars (including console codes / colours) from script output

If we redirect output to file in this pattern top >> somefile.txt, we get lot of garbage value in the output. But for top there is batch (top -b -n1 >> somefile.txt) option where the file output is as desired. In case of programs like nethogs there is no such options. Is there is good way to output in such case.

share|improve this question

marked as duplicate by Gilles, jasonwryan, Renan, phunehehe, jw013 Oct 9 '12 at 16:25

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

    
I would say that the best thing to do is to write to the authors of nethogs requesting they add a mode similar to top -b. –  Random832 Oct 8 '12 at 15:09
    
I created a comment saying this is not a duplicate, but when I try to edit the title of this question to express the real question it becomes "How to clean the output of an ncurses program?", which is clearly a duplicate. Voted to close. –  phunehehe Oct 9 '12 at 12:59
    
for nethogs, may be these options are new? nethogs -t or nethogs -b, check here also –  Aquarius Power Jun 18 at 23:40
add comment

2 Answers 2

You can also try filtering out the garbage yourself. For example, this would remove all the non-printable characters:

nethogs | sed 's,[^[:print:]],,g' >> somefile.txt

You can extend that as needed or take the opposite approach and only allow explicit non-garbage to come through, eg. (alphanumerics and punctuation):

nethogs | sed 's,[^[:alnum:][:punct:]],,g' >> somefile.txt

If the output is color coded, some extra work is needed to strip out the color escape strings.

share|improve this answer
add comment

There isn't a good way, but sometimes setting the terminal can help.

E.g.,

TERM=dumb top

gets rid of most control characters.

share|improve this answer
add comment

Not the answer you're looking for? Browse other questions tagged or ask your own question.