LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices

Reply
 
Search this Thread
Old 11-17-2006, 07:01 AM   #1
tphyahoo
LQ Newbie
 
Registered: Jun 2006
Posts: 4

Rep: Reputation: 0
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>
 
Old 11-17-2006, 08:26 AM   #2
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 385

Rep: Reputation: 33
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:~$

Last edited by vxc69; 11-17-2006 at 08:30 AM.
 
Old 11-17-2006, 08:57 AM   #3
pixellany
LQ Veteran
 
Registered: Nov 2005
Location: Annapolis, MD
Distribution: Arch/XFCE
Posts: 17,802

Rep: Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728Reputation: 728
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.
 
Old 11-18-2006, 01:25 AM   #4
jschiwal
Guru
 
Registered: Aug 2001
Location: Fargo, ND
Distribution: SuSE AMD64
Posts: 15,733

Rep: Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654Reputation: 654
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.
 
Old 11-18-2006, 03:56 AM   #5
vxc69
Member
 
Registered: Jul 2004
Distribution: Ubuntu
Posts: 385

Rep: Reputation: 33
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.
 
Old 11-19-2006, 01:17 PM   #6
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,533

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


Reply

Tags
grep, man, pager


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
MAN not found or nor installed ???? Need help touny AIX 2 11-12-2005 01:51 AM
[SOLVED] [vi|man|less] covers/erases previous screen output zedmelon Linux - Software 4 01-10-2005 06:11 PM
BASH: Output everything between two strings systemparadox Programming 2 12-18-2004 10:26 AM
grepping last word of output rajatgarg Programming 3 11-25-2003 10:41 AM
grepping for multi-line output born4linux Programming 1 03-07-2003 02:26 AM


All times are GMT -5. The time now is 02:13 PM.

Main Menu
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration