How to get specific section inside a MAN page? - manual

I want to get only specific sections of MAN page inside a shell (or perl) script and print it.
For eg: only the SYNOPSIS section of MAN page
Is there any standard way to do that?
Regards,
Anandan

Not as far as I know, but you can search by typing '/' followed by the text you want to search for, then press 'n' repeatedly to go to the next match, or 'N' to go to the previous match.

I haven't played with Linux/Unix in a long while, but perhaps you can perform a:
man MANPAGE|a2ps -m > grep -A 1000 SYNOPSIS

Type the '/' key, then type the string you want to search for (you'll see your query at the bottom of the terminal as you type) and press enter. It'll highlight all the matches and take you to the first one. After that, type '/' and press enter to go to the next match.

If you want to navigate to a specific section of a man page you can use this handy method:
Definition
man2() {
man -P 'less -p ^EXAMPLES' $1
}
Example
man2 stat

at the end of a man page you may find something like a command(some-number) where
that (some-number) is the section that contains that command in man pages
so I use the -K switch (note it is a big K) followed by the specified section number and it works for me:
`man -K section_number term_or_command`
i.e.
man -K 5 /etc/host.conf

Related

Read man page or file from certain row

Is there a way to read a man page from a certain row?
I grepped for a specific flag in a man page and saw what line it was in, is there a way start reading the man form that line?
man uses $MANPAGER or $PAGER, so it depends on what you're using. To start reading the manpage for foo at the first match of 'pattern', you might try:
MANPAGER='less -p pattern' man foo
or (assuming ${MANPAGER-PAGER} is less):
LESS+='-p pattern' man foo

is there a special search command for options and commands in man-pages (in less)?

Question: using the less command in any linux shell (i'm using bash as probably most people do), is there a way to search a file only for it's commands or options?
So, to be more precise:
if i want to quickly find the description for one special option in a man-page,
is there a special search syntax to quickly jump to the corresponding line explaining that specific command?
example:
if i type:
man less
and i want to quickly find the description for the "-q" command,
is there a search syntax to directly jump to that line?
If I type /-q, it finds all occurences of "-q" everywhere in the file, so I get around 10-20 hits, of which only one is the one i was looking for..
So I'm just hoping there is a better/quicker way to do this..
(not to important though :D)
In man, options are generally described with the option name in bold at the start of the line.
So, if you are looking for the option -q, then the search command would be /^\s*-q\>
The regex ^\s*-q\> reads as follow:
^ start of a line
\s* any number of spaces (including none)
-q the option name you are looking for
\> the end of the word

Vim keyboard shortcut general word count

How do I count the words in a document in vim? According to vim's definition of a word.
Seems easy to answer however I couldn't find an answer on here as they all addressed word matches, or having it in a function. I just want the word count.
You may also find it useful to know that you could find the answer yourself using helpgrep.
e.g.
:helpgrep count words
You can then use :cnext to flip through the search result. Result #2 in this case is what you need.
The keyboard shortcut is g Ctrl-g.
Thanks - Assaf Lavie
For further information about the usage of this see :help g
Thanks - Munen
For those who have access to the GNU coreutils (E.G Linux) you can use the program wc see man wc for more information
:!wc -w %<tab>
The %tab expands to the current file in the buffer
I like using standard shell commands for such tasks. Therefore I would pipe the text to wc. Highlight the lines you want to count the words in, then:
:!wc -w
This will replace the text with the actual wordcount. Of course you can bring back your text by undoing the last action with u.

In reverse-i-search (Ctrl+R ) ,Any method to switch between similar commands in history

I think an example will be good to understand my question.
...
scp file1 user10#192.168.10.1:/home/user1/linuxfiles/samplecode/important
...
...
scp file1 user10#192.168.10.1:/home/user1/linuxfiles/samplecode/important/tested
...
...
Assume that is the order of commands in history. If I am doing Ctrl+R and type scp it will show the last executed scp command ( ie the line ending with 'tested') .
But I want to locate the scp command ending with 'important'. So is there any way in this reverse-i-search to view all commands starting with scp, to choose the appropriate one?
Keep pressing Ctrl-R and it will traverse your history.
If your search terms are a bit more complicated/ not contiguous, another option is to grep among the history results, e.g.:
history 300 | grep scp | grep important$
This will return a list of commands in your history that match, such as:
3323 scp file1 user10#192.168.10.1:/home/user1/linuxfiles/samplecode/important
3325 scp file1 user10#192.168.10.1:/home/user1/winfiles/samplecode/important
And you can then execute the relevant command with !3325.
I sometimes find this useful when running a lot of similar commands and may have to press Ctrl+R many times to get back to the exact command.
There is great alternative to Ctrl+R
install https://github.com/dvorka/hstr
run it with hh
it shows a list of you all the last commands executed (contents of ./bash_history)
if you start typing the list will be filtered based on what you type
you can use Up/Down arrows to select the desired command and select it with Enter
I found this great tool mcfly as a replacement to the traditional Ctrl+R and it works really well. Basically you can see ALL the results as you type and you can select the command you are looking for. You can also customize the layout etc. I really recommend it.
https://github.com/cantino/mcfly

Dynamic abbrev expand for the shell

Is there a function on one of the linux shells like the emacs dabbrev-expand?
First to give a definition:
M-xdescribe-functionEnterdabbrev-expandEnter
...
Expands to the most recent, preceding word for which this is a prefix.
Given that bash seems to be most heavily influenced by Emacs, looking there first reveals a few possibilities:
man bash(1), readline section
dynamic-complete-history (M-TAB)
Attempt completion on the text before point, comparing the text
against lines from the history list for possible completion matches.
dabbrev-expand
Attempt menu completion on the text before point, comparing the text
against lines from the history list for possible completion matches.
By default (or my system at least), M-/ is already bound to complete-filename:
$ bind -l | grep /
"\e/": complete-filename
You could re-bind it by putting
"\e/": dabbrev-expand
in your ~/.inputrc or /etc/inputrc.
Note that it only seems to complete the first word (the command), and only from history, not from the current command line as far as I can tell.
In zsh, I can't see anything in the man page that does this, but it should be possible to make it happen by figuring out the appropriate compctl command (Google mirror).

Resources