Code, Computers & Random Junk

Output Manuals in Terminal

When using the pipe function i Terminal, it’s usually fine. It takes your input and makes a text file of it.


something here > goes_here.txt

That works fine for most anything but manuals. When you send a manual to a text file like:

man grep > grep_manual.txt

You’ll end up with a lot of ddoouubbbblleedd letters etc. It will look something like this in your text file:

    ggrreepp [_o_p_t_i_o_n_s] _P_A_T_T_E_R_N [_F_I_L_E...]
    ggrreepp [_o_p_t_i_o_n_s] [--ee _P_A_T_T_E_R_N | --ff _F_I_L_E] [_F_I_L_E...]

To get around this - use col -b in your input and it removes the backspace and the bold text (eg making a plain text file).

So, here we go again…

man grep | col -b > grep_manual.txt

Nice & clean. :)

Or you make an function.

# manOut grep                   // grep_manual.txt (in pwd)
# manOut grep ~/Desktop/grep    // ~/Desktop/grep_manual.txt
function man2txt()
    if [[ "$2" == '' ]]; then _path="$1"; fi
    man $1 grep | col -b > $_path_manual.txt


A new thing in OS X Lion is another way to bring up the manuals. Just control-click/right-click on the function you need to consult the manual for, and chose to open the manual page.

A new window with a yellow’ish background opens up with the manual in it.

You can actually use that on any word. If the manual is missing it opens up blank. From that window you can save it as normal with ⌘+S.

Another OS X function is that you can open the man page with:

open x-man-page://foobar;

A function for that would be:

# open man-page(s) in its own window. Use: "manx" instead of "man" (OS X)
function manx() { local i; for i; do open x-man-page://$i; done; }


manx foobar

Or open more manuals at once…

manx foo bar baz