LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 07-22-2010, 06:45 AM   #1
borgibo
Member
 
Registered: Aug 2007
Posts: 47

Rep: Reputation: 15
Smile grep command


Hello,

I am trying to use the grep command but I cannot manage, I know it can be done so I need help.

I am connected to the sane site and I have its sane supported devices for linux table on my xorg screen.

And I want to "grep" and print from the 1777 registered devices the 333 scanners that have complete support.

I tried:"$ grep xorg sane scanners complete" which of course is silly, wishing to tell grep that the file is at the screen etc! I got "no such file". I tried other silly commands to no avail.

I will be thankful for your help,

borgibo
 
Old 07-22-2010, 07:05 AM   #2
Andrew Benton
Senior Member
 
Registered: Aug 2003
Location: Birkenhead/Britain
Distribution: Linux From Scratch
Posts: 2,073

Rep: Reputation: 64
What application is displaying the data on that screen? A terminal? A text editor? A browser? If it's Firefox, you can search for text in the page by pressing Ctrl-f.
To use grep you will need to save the data to a text file.
 
1 members found this post helpful.
Old 07-22-2010, 07:05 AM   #3
camorri
LQ Guru
 
Registered: Nov 2002
Location: Somewhere inside 9.9 million sq. km. Canada
Distribution: Slackware 14.1, 14.2
Posts: 5,090

Rep: Reputation: 483Reputation: 483Reputation: 483Reputation: 483Reputation: 483
I have never tried to use grep by itself. It is a program that 'filters' input, and gives you the filtered output matches.

Example. If you go to your home directory, and run the command 'ls', the output to the screen will be the files and directories that are not hidden. There may be many lines. If you are looking for all directories and files with a letter f in them ( just an example ) the command 'ls | grep f' would do it. The input comes from ls. The vertical bar is the 'pipe' command. It directs the output of ls to grep. Grep does the filtering you set up, in this trivial example the filter is 'f'.

You could search through a file is you used the 'cat' command. ie 'cat myfile | grep stuff'. The output would be a line for every time 'stuff' appears in the file.

Hope this helps.
 
1 members found this post helpful.
Old 07-22-2010, 07:07 AM   #4
Wim Sturkenboom
Senior Member
 
Registered: Jan 2005
Location: Roodepoort, South Africa
Distribution: Slackware 10.1/10.2/12, Ubuntu 12.04, Crunchbang Statler
Posts: 3,786

Rep: Reputation: 282Reputation: 282Reputation: 282
Maybe I misunderstand what your doing: You have a website open in a browser (e.g. firefox) and try to grep in there? That does not work. Grep works on a file, not on a screen.

I did the following:
saved http://www.sane-project.org/sane-mfgs.html as a text file (sane.txt); do not save a s webpage as it contains to much crap for this purpose
next I ran the command below
Code:
grep -i complete sane.txt >complete.txt
The -i will make the grep case insensitive and the output goes to a file complete.txt

PS
For more complex stuff (e.g. scanner and complete), you can pipe the output of the first command through a pipe to a new grep (for scanner) and redirect the output to e.g. scanner_complete.txt

Last edited by Wim Sturkenboom; 07-22-2010 at 07:11 AM.
 
1 members found this post helpful.
Old 07-22-2010, 07:12 AM   #5
syg00
LQ Veteran
 
Registered: Aug 2003
Location: Australia
Distribution: Lots ...
Posts: 14,842

Rep: Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823Reputation: 1823
Presuming you are looking at a web page, use something that understands http, but doesn't render the page - curl is good. Pipe it straight into grep, or save it to a file for processing.
 
1 members found this post helpful.
Old 07-22-2010, 09:50 AM   #6
borgibo
Member
 
Registered: Aug 2007
Posts: 47

Original Poster
Rep: Reputation: 15
Thank you everybody, I did not expect such a fast answer so I did lose some time.

Here is what I am trying to do first i.e. save the firefox sane page "http://www.sane-project.org/sane-mfgs.html" to a file. So I went: "$ mkdir sane.txt" and made a directory (that is a file?) in my home. Then I tried to save the sane page as text from firefox bar: file>save page as>home>jv>sane.txt but it does not go (saved) to sane.txt. I tried to save the page as text and as full page.So here I am stuck! You understand that I know almost nothing about computing.
 
Old 07-22-2010, 10:42 AM   #7
borgibo
Member
 
Registered: Aug 2007
Posts: 47

Original Poster
Rep: Reputation: 15
Sorry but I had already saved the page as text in my home. It did not save itself in the recently made "sane.txt" directory which I was informed about after trying to save the page simply in /home, experimenting!
then I ran:grep -i complete sane.txt >complete.txt but got: there is no such file or directory.
 
Old 07-22-2010, 11:22 AM   #8
borgibo
Member
 
Registered: Aug 2007
Posts: 47

Original Poster
Rep: Reputation: 15
Smile

I did try the following successfully: "cat sane-mfgs.html | grep Complete" and I got all scanners with complete Linux support and some with complete no support!

I had some difficulty to print the 10 resulting pages as I had to manually
'print screen', neither xterm or konsole would print the whole page.

That was a very good lesson for me and thank you all for your support and time. I know that it is frustrating for a teacher who faces somebody like me that lacks the basics.


Thank you very much again,

borgibo
 
  


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



Similar Threads
Thread Thread Starter Forum Replies Last Post
How to pass the result of a command to another command (like grep) desb01 Programming 4 06-25-2009 01:09 PM
Help me in Grep Command + cd command in single line JeiPrakash Linux - Newbie 3 05-27-2008 05:16 AM
grep command sgarci Linux - General 3 08-28-2006 08:13 AM
how to use grep command sharonyiisl Linux - Newbie 7 05-28-2006 04:46 PM
grep command cuss Linux - General 7 02-14-2003 10:23 AM


All times are GMT -5. The time now is 08:50 PM.

Main Menu
Advertisement
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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration