Afficher un message
Vieux 29/10/2006, 06h02   #3
Barry Margolin
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Using the grep command to filter

In article <84iri4dtde.fsf@ripco.com>, comp@toddh.net (Todd H.)
wrote:

> transmute70@gmail.com writes:
>
> > Hello Everyone,
> >
> > I am a college student currently enrolled in a Unix class. Unix is in
> > no way shape or form related to my major, and needless to say, I'm
> > stumped.

>
> Finally someone asking for with a homework question coming clean
> and saying it's a homework question. Now this is the student I'd like
> to learn the material.
>
> > The question I must answer is this:
> >
> > "Enter a single command-line that would find out the 5 files in/under
> > /etc that contain the string 'ubuntu,' case insensitively, more than
> > any other file in/under the /etc directory. Sort the list from most to
> > least and throw away standard error."

>
> Okay, so let's break this down. We need to find all files in /etc/
> that ubuntu Ubuntu UBUNTU ubunTU whatever in them. Grep is the tool
> for the job. grep ubuntu /etc/* of course. But that will do a case
> senstive search. I'll bid you to consult
> $ man grep
>
> to find the one option you need to add to the grep command to make the
> search case insensitive.
>
> Now look at the output of that grep command will give you all the
> lines of text in all the files in /etc with ubuntu in em. You may
> even notice filenames at the beginning of each matching line.
> Hrmm... maybe we can't just to a grep and maybe we need to start with
> another command to operate on each file one at a time.


You could also use the option to grep that tells it to just print the
count of matches, rather than the matching lines themselves.

>
> Big Hint: your one big ole command might start with a find /etc -exec
> command and in the -exec clause, think about grep, wc, then maybe
> piping that output somehow into sort finishing off with head -5
> might be the ticket.


If you use the option to print the count of matches, you don't need to
use wc at all.

>
> > I can do each part the question asks separately, but I've no idea how
> > to put this all together to create a single working command. Any
> > would be greatly appreciated.

>
> I think the "one file at a time" operation that find /etc -exec
> brings to the table might be the concept you're looking for.


Not if you use the -c option to grep.

>
> Another approach might involve a shell for loop.
>
> Work on it a while and come back with follow on questions.
>
> Best Regards,


--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***
*** PLEASE don't copy me on replies, I'll read them in the group ***
  Réponse avec citation
 
Page generated in 0,08258 seconds with 9 queries