LinuxQuestions.org
Visit the LQ Articles and Editorials section
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices

Reply
 
Search this Thread
Old 06-14-2013, 05:50 AM   #1
dansimon
Member
 
Registered: Jun 2013
Location: Norway
Distribution: Slackware
Posts: 50

Rep: Reputation: Disabled
Read from stdin in man?


Hi,

I have a script where I manually extract info from a man page, I need to format this to readable text and then display it in a pager.

script | man --or-- man | script

does not work, because man searches for a man page not given to it and ignores the script input.

script | less

would not work because it would display the man page unformatted, which is not very readable.

I have tried looking at groff and groffer, but without success. Any ideas??

Last edited by onebuck; 06-16-2013 at 06:38 AM. Reason: correct title
 
Old 06-14-2013, 06:09 AM   #2
validator456
Member
 
Registered: Apr 2013
Location: Rotterdam, The Netherlands
Distribution: Crunchbang Linux
Posts: 80

Rep: Reputation: Disabled
I am not really sure what you want. Is this what you want?
Quote:
man ls > ls.txt
 
Old 06-14-2013, 06:12 AM   #3
dansimon
Member
 
Registered: Jun 2013
Location: Norway
Distribution: Slackware
Posts: 50

Original Poster
Rep: Reputation: Disabled
no, I whant to render a man page that is not in the system (/usr/man...), but that is embedded within my script. Therefor I need either man to read my input directly instead of searching for an appropriate man page, or I need to manually render the manpage format to readable text then display this in a pager.
 
Old 06-14-2013, 08:00 AM   #4
dansimon
Member
 
Registered: Jun 2013
Location: Norway
Distribution: Slackware
Posts: 50

Original Poster
Rep: Reputation: Disabled
nroff -man <input_file> > <output_file> && less <output_file>
Would work, but this is not at all an elegant solution for a bash script, because it would require a lot of I/O with temporary files.

Is there a way to <read_raw_text> | <format_to_readable_text> | <display_text> ?
Neither man nor nroff nor any other tool I have looked at seems capable of doing this.

Any suggestions?
 
Old 06-14-2013, 08:52 AM   #5
dansimon
Member
 
Registered: Jun 2013
Location: Norway
Distribution: Slackware
Posts: 50

Original Poster
Rep: Reputation: Disabled
Solved the issue, you can point man to a non-standard file. My initial tests failed because of a syntax error in the man page

file | man does not seem to work, but I worked around this by
using temporary files in memory ie:

cat file > /dev/shm/file
man /dev/shm/file

I don't particularly like this solution (it's ugly), but it works. marking this as SOLVED
 
Old 06-14-2013, 01:17 PM   #6
rknichols
Senior Member
 
Registered: Aug 2009
Distribution: CentOS
Posts: 1,424

Rep: Reputation: 598Reputation: 598Reputation: 598Reputation: 598Reputation: 598Reputation: 598
The man command will read from stdin if you tell it to:
Code:
cat file | man /dev/stdin
or from a here-document:
Code:
man /dev/stdin <<EOF
   [insert your manpage source here]
EOF
 
Old 06-18-2013, 02:56 AM   #7
dansimon
Member
 
Registered: Jun 2013
Location: Norway
Distribution: Slackware
Posts: 50

Original Poster
Rep: Reputation: Disabled
Wow, thanks! I did not know about /dev/stdin, this is just the elegant solution I was searching for
 
  


Reply


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 On
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
unable to print using acroread on a node.....Acro read problem(lp: Error - stdin ) vsyed786 Linux - Enterprise 2 01-18-2012 04:28 AM
[SOLVED] Read from stdin in perl, do not wait for EOF smeezekitty Programming 1 04-28-2010 03:17 PM
read from stdin in a shell script bujecas Linux - General 3 07-03-2009 04:46 PM
after redirecting stdin still need to read data from keyboard vrikers Programming 4 10-31-2004 06:11 AM
How to Read a Troff Man File steve65 Linux - Software 7 10-20-2002 07:35 PM


All times are GMT -5. The time now is 07:26 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