Re: Help w/ matching grep and regular expressions

From: Nick Landsberg (hukolau_at_NOSPAM.att.net)
Date: 03/11/04


Date: Thu, 11 Mar 2004 04:07:19 GMT

Alan Connor wrote:

> On Thu, 11 Mar 2004 03:18:25 GMT, WH <nos.pam@email.com> wrote:
>
>>
>>I'm doing an assignment for a unix class, but I'm stuck on two questions.
>>
>>3. Write a command that removes all files that end in a ".log" extension,
>>and do not contain the string "west". Remove them form your home directory,
>>and all subdirectories, recursively.
>>
>
>
> Here's one way:
>
> find . -type f -and \( -name '*.log' -and ! -name '*west*' \) -exec rm {} \;
>
> The ! means NOT in this situation.

This is actually more elegant than the solution I suggested,
but either would work. My suggestion (in another
reply) would not work if there was a subdirectory with
the substring "west" tho.

>
>
>
>
>>4. Write a command that produces the 'ls -l" output for the current
>>directory, but only lists files and directories for which the "other"
>>category (as opposed to "user" and "group" has execution permission.
>>
>
>
> One way:
>
>
> ls -l | grep '^...[^x]..[^x]..x'
>
> (there's an intro to regular expressions on the webpage in my sig)
>
>
>>With number 3, if I ignore the part about west, I would do a
>>
>> find . -name *.log | xargs rm
>>
>>But with the west there, I know I want to grep it, and have grep say
>>something like "match all lines except those with 'west'" but I can't figure
>>out how to do it. I scoured the web for an hour, and all I could find for
>>"except" was the ^carrot, which is useless here.
>>
>
>
> You can do:
>
> grep '*.log' | grep -v 'west'
>
>
>>With number four, since permissions always have ten characters, I'd want to
>>match anything w/ ten characters, ending in x. I've got no idea how to
>>match the end of a word, just the end of a line w/ $.
>>
>
>
> ^ matches the beginning of a line, except when within [] where it means
> DON'T match the following characters in the [].
>
> Be sure to play with these. Make a directory tree in your $HOME and
> put files in it to play with. I call the top directory in mine play/ :-)
>
>
>
> AC
>

-- 
Ñ
"It is impossible to make anything foolproof because fools are so 
ingenious" - A. Bloch


Relevant Pages

  • Re: Help w/ matching grep and regular expressions
    ... > I'm doing an assignment for a unix class, but I'm stuck on two questions. ... > and all subdirectories, recursively. ... > But with the west there, I know I want to grep it, and have grep say ... > With number four, since permissions always have ten characters, I'd want ...
    (comp.unix.questions)
  • Re: Help w/ matching grep and regular expressions
    ... > I'm doing an assignment for a unix class, but I'm stuck on two questions. ... > and all subdirectories, recursively. ... > But with the west there, I know I want to grep it, and have grep say ... > With number four, since permissions always have ten characters, I'd want to ...
    (comp.unix.questions)
  • Summary: Grep, Sed, Awk - timestamp range for those non "fluent"
    ... This is what I find out to be the most flexible and easy to use (with inspiration from Ragnar Moller's suggestion): ... Following this summary from Ragnar Moller, may experts out there advise how do I grep syslog messages with format of: ... ## we found start line containing cecilia ... frederick lines and only displaying the information between those ...
    (SunManagers)
  • Re: Times.. they are strange... they are lost.... times... where are the old guard? Where is my old
    ... and there's a strong suggestion of cumulative ... past brain abuse of various kinds taking it's toll as well. ... before coming back to get stuck in to the debate. ... and Ollie cuts in: 'And shome bloody GREAT birds too' ...
    (soc.culture.irish)
  • Re: How to make File/Search work?
    ... "Suzanne S. Barnhill" wrote in message ... Here's what I've got (following Suzanne's suggestion): ... selected, both with the "...and subdirectories" option, although it ...
    (microsoft.public.word.docmanagement)