Re: Using the grep command to filter



transmute70@xxxxxxxxx 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 help with a homework question coming clean
and saying it's a homework question. Now this is the student I'd like
to help 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.

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.

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 help
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.

Another approach might involve a shell for loop.

Work on it a while and come back with follow on questions.

Best Regards,
--
Todd H.
http://www.toddh.net/
.



Relevant Pages

  • Re: Using the grep command to filter
    ... I am a college student currently enrolled in a Unix class. ... that ubuntu Ubuntu UBUNTU ubunTU whatever in them. ... grep ubuntu /etc/* of course. ... Now look at the output of that grep command will give you all the ...
    (comp.unix.shell)
  • Re: Using the grep command to filter
    ... that ubuntu Ubuntu UBUNTU ubunTU whatever in them. ... grep ubuntu /etc/* of course. ... Now look at the output of that grep command will give you all the ... i.e. lines, containing the pattern. ...
    (comp.unix.shell)
  • Re: Using the grep command to filter
    ... that ubuntu Ubuntu UBUNTU ubunTU whatever in them. ... grep ubuntu /etc/* of course. ... Now look at the output of that grep command will give you all the ... i.e. lines, containing the pattern. ...
    (comp.unix.shell)
  • Re: MacTeX 2007 and documentation
    ... may be the most useful command available when doing searches at the ... will find every file on your system that has the text "memoir" on it, ... If locate generates 30 lines of text, where each line is a file, grep ... I need a Unix guru to chat to for half an hour or so to put me straight. ...
    (comp.text.tex)
  • Re: piping multiple selections to mv or cp and exclusion
    ... pipe to shell to execute each command statement ... Unix is indeed lifelong learning :-) ... and the regexp. ... back into the grep statement. ...
    (comp.unix.shell)