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.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am running CentOS 6 and I am trying to grep the output of top and redirect it to a file.

I.e.

top -u user1 -n 1 | /bin/grep somecommand &> scratch.txt

The output of vim scratch.txt is

^[(B^[[m21329 user1    20   0 2855m 816m 757m S 607.2  1.3  86:36.36 somecommand                                                     ^[(B^[[m^[[39;49m

The output of cat scratch.txt is

21329 user1    20   0 2855m 816m 757m S 607.2  1.3  86:36.36 somecommand

QUESTION : Why do I see funny characters in vim and how do I get rid of them?

share|improve this question
    
add -b for batch mode – Rui F Ribeiro Jan 15 at 15:23
    
That is a winner, add as answer please. – irritable_phd_syndrom Jan 15 at 15:24
    
Browsing this at work. Enjoy. – Rui F Ribeiro Jan 15 at 15:26
up vote 10 down vote accepted

tops default output is intended for terminal. As such is uses various control codes (invisible when viewed in a terminal). Those include various ways to move around the screen. Style output etc.

To get a more friendly output for text files / editing or what ever use the batch mode.

top -b ...
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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