• Welcome to Computer Association of SIUE - Forums.
 

"man netstat >> filename" question

Started by Michael Kennedy, 2002-11-12T18:13:55-06:00 (Tuesday)

Previous topic - Next topic

Michael Kennedy

I'd like to save a few man pages into another file for emailing or reading later, but when i use "man netstat >> filename" to dump the text into a file I get the formatting charectors as well as text.  Is there a good way to just get the text and not the extra junk that makes it pretty unreadable?  TIA.
"If it ain't busted, don't fix it" is a very sound principal and remains so despite the fact that I have slavishly ignored it all my life. --Douglas Adams, "Salmon of Doubt"

bill corcoran

after reading your post i tried to do the same for myself, and it bugged the hell out of me.  it kept on having the "^H" symbol immediately following a character that should not be there.  now, i know there has got to be an easier way to do this, but being the inexperienced beginner i am, i could only think of writing a program that would fix it.  this is what i did on my system:

1.  i typed:
$ man netstat > netstat.man

($ is my bash prompt, > is replace >> is append)

2. use vim to create cleanman.cpp file with this code:

#include

int main(){
   char tmp1, tmp2;

   cin.get(tmp1);
   while(!cin.eof()){
      cin.get(tmp2);
      if(tmp2!='\b'){
         cout << tmp1;
         tmp1 = tmp2;
      }
      else if(!cin.eof())
         cin.get(tmp1);
   }
   return 0;
}

/* this code deletes all the ^H's (or \b chars), and the char immediately before them, and prints all other chars to stdout/cout */

(I know the code looks a little weird, the msg board got rid of my formatting, but trust me, it does just what i want)

3.  then type the following to create the binary:
$ g++ -o cleanman.exe cleanman.cpp

4.  then type this:
$ cleanman.exe netstat.txt

(this makes netstat.man the stdin/cin, and netstat.txt the stdout/cout)

Hopefully that does it for you, because it worked for me.  Let me know what happens.
-bill

Michael Kennedy

Dang, I didnt even think about writing a little app to do that for me.  Thanks for doing that, man.  I guess I should have done that before I posted up here, but it didn't even occur to me.  I was hoping that Linux had a way of dealing with that itself, but a hack is no worse a solution than anything else.  :)

Thanks again, man.

PS- Worked perfectly.

Next question- How can I get this to do that all the time?  For example, if it possible to do a:
man netstat >>> netstat.txt
and have it strip the text automatically?  (>>> can be anything, btw...)
"If it ain't busted, don't fix it" is a very sound principal and remains so despite the fact that I have slavishly ignored it all my life. --Douglas Adams, "Salmon of Doubt"

Peter Motyka

You could have the littleapp read from stdin and pipe the man output to it.  I am not too sure if this weill work, but it seems resonable.  If you have littleapp read from stdin, then the following command should work...

$ man netstat | littleapp > file

To reduce the chain of command, you could have littleapp output to a file by default rather than having to redirect its output.

Peter
SIUE CS Alumni 2002
Grad Student, Regis University
Senior Engineer, Ping Identity
http://motyka.org

Kade P. Cole

Another thing I like to do is just goto google.com and type in man netstat or whatever. I always seem to find an html version of the man page that way. There are also alternative man viewers and should be some that will allow you to print nicer. Hope this helps.

Kade
Kade
--------------------------------------
Most people HAVE to use a PC.
I GET to use a MAC with OS X!

bill corcoran

hey remember how i said i knew there was an easier way?  well now i know what that easier way is...

$ man man

then look at the bottom:

>       To  get  a  plain  text  version  of a man page, without backspaces and
>       underscores, try
>
>         # man foo | col -b > foo.mantxt


don't know about you guys, but i feel silly now.
-bill

Michael Kennedy

Heh, heh...  I can't believe I didn't look there first.  I'm usually the one telling people to RTFM, not noe who needs to RTFM himself.  Sorry bill.  :)  Thanks for all the help, though.  It was a fun exercise, though, right?  :)
"If it ain't busted, don't fix it" is a very sound principal and remains so despite the fact that I have slavishly ignored it all my life. --Douglas Adams, "Salmon of Doubt"

bill corcoran

yeah i'm embarassed, generally being an advocate of the RTFM problem solving strategy myself (though reading the manual is not always feasible or even possible, it was certainly not the case this time).  i guess the challenge of figuring things out by yourself can prove to be more entertaining.

as one of my childhood heroes would put it, sgt. slaughter to be specific that is,

"now you know, and knowing is half the battle."

-bill