LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   puzzled by grepping on man output -- some strings found, others not (https://www.linuxquestions.org/questions/linux-software-2/puzzled-by-grepping-on-man-output-some-strings-found-others-not-502481/)

tphyahoo 11-17-2006 07:01 AM

puzzled by grepping on man output -- some strings found, others not
 
I'm attempting to grep on man output for convenience, and had the following curious result. The first search is picked up, but the second search (on "bashrc") has no results.

I guess this question basically boils down to a sane way of getting man output to stdout so I can pipe it to wherever. -P cat probably isn't the right way to do this.

so what is?

$:~/shellenv> man -P cat bash | grep "executes commands from"
in that order, and reads and executes commands from the first one that
reads and executes commands from ~/.bashrc, if that file exists. This
reads and executes commands from ~/.bashrc, if that file exists and is
$:~/shellenv> man -P cat bash | grep "bashrc"
$:~/shellenv>

vxc69 11-17-2006 08:26 AM

This is what I get:

Code:

@FREEWILL:~$ man -P cat bash | grep "executes commands from"
Reformatting bash(1), please wait...
      in that order, and reads and executes commands from the first one  that
      reads and executes commands from  /etc/bash.bashrc  and  ~/.bashrc,  if
FREEWILL:~$ man -P cat bash | grep "bashrc"
Reformatting bash(1), please wait...
              ization file /etc/bash.bashrc and the standard personal initial‐
              ization  file ~/.bashrc if the shell is interactive (see INVOCA‐
              /etc/bash.bashrc and the personal initialization file  ~/.bashrc
      reads and executes commands from  /etc/bash.bashrc  and  ~/.bashrc,  if
      from file instead of /etc/bash.bashrc and ~/.bashrc.
      reads  and  executes  commands  from /etc/bash.bashrc and ~/.bashrc, if
              initialize the shell, as in ~/.bashrc.  The value of BASH_ENV is
      /etc/bash.bashrc
      ~/.bashrc
@FREEWILL:~$


pixellany 11-17-2006 08:57 AM

These both work on my machine (Mepis/bash shell):
man bash|grep bashrc
man bash|grep "bashrc"

Note that the quotes are not required in grep unless you have a regex or the search string has whitespace.

jschiwal 11-18-2006 01:25 AM

The output from man will contain backspaces and underline characters. The instances of "bashrc" in the manpage appear as bashrc. That is why your grep doesn't find them. You could instead pipe the output of the manpage through the "col" command.

man bash | col -b | grep bashrc
Reformatting bash(1), please wait...
tialization file ~/.bashrc if the shell is interactive (see
~/.bashrc if the shell is interactive. This option is on by
reads and executes commands from ~/.bashrc, if that file exists. This
~/.bashrc.
reads and executes commands from ~/.bashrc, if that file exists and is
initialize the shell, as in ~/.bashrc. The value of BASH_ENV is
~/.bashrc

Of course it would be better to use the '/' key to start a search when reading a manpage.

vxc69 11-18-2006 03:56 AM

Quote:

Originally Posted by jschiwal
Of course it would be better to use the '/' key to start a search when reading a manpage.

Now that would be really useful. Wish I had known this earlier. :D

Mara 11-19-2006 01:17 PM

Moved: This thread is more suitable in Linux-Software and has been moved accordingly to help your thread/question get the exposure it deserves.


All times are GMT -5. The time now is 09:31 AM.