Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.
man find

opens up the man page for find in my pager.

Is there something like

example find

that would print

find /usr/lib -name "stdint.h"
share|improve this question
1  
I'm not entirely sure if I understand you correctly: Are you just looking for examples for common commands? Note that many manpages have a section dedicated to examples. –  slhck Jul 30 '12 at 21:08
    
Yes, that's what I'm looking for. Is there a quick way to just print the examples? –  William Bettridge-Radford Jul 30 '12 at 21:09

1 Answer 1

up vote 4 down vote accepted

Is there a quick way to just print the examples?

Yes.

 man find | perl -ne 'print if /^EXAMPLE/.../^[A-Z]/'

Similar solutions must exist using awk etc

 man find | awk '/^EXAMPLES/,/^EXIT/ { print }'
share|improve this answer
    
Notes: On Mac OS X, the specified perl invocation fails because the output of man actually contains E\bEX\bXA\bAM\bMP\bPL\bLE\bE', where \b` is backspace; if you do can pass those backspace characters to perl, it works. However, perl doesn't seem to interpret the actual sequence \b like that, so the only way I've found is with bash's $'' quoting: man find | perl -ne $'print if /^E\bEX\bXA\bAM\bMP\bPL\bLE\bE/.../^[A-Z]/'. –  echristopherson Aug 5 '12 at 22:57
    
Continued: I can't get the awk example to work; EXIT doesn't occur right after the EXAMPLES section in OS X, and awk on OS X doesn't work with [A-Z], but at least it does recognize \b. –  echristopherson Aug 5 '12 at 22:57
    
You can probably prefix the command with TERM=something to prevent man inserting special formatting characters. Perhaps man on OSX has some options fo this? –  RedGrittyBrick Aug 6 '12 at 8:34

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.