Re: Help w/ matching grep and regular expressions
From: Nick Landsberg (hukolau_at_NOSPAM.att.net)
Date: 03/11/04
- Next message: Allan Chandler: "Re: Help w/ matching grep and regular expressions"
- Previous message: Tom: "UNIX Timing"
- In reply to: Alan Connor: "Re: Help w/ matching grep and regular expressions"
- Next in thread: Nick Landsberg: "Re: Help w/ matching grep and regular expressions"
- Reply: Nick Landsberg: "Re: Help w/ matching grep and regular expressions"
- Reply: Alan Connor: "Re: Help w/ matching grep and regular expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Allan Chandler: "Re: Help w/ matching grep and regular expressions"
- Previous message: Tom: "UNIX Timing"
- In reply to: Alan Connor: "Re: Help w/ matching grep and regular expressions"
- Next in thread: Nick Landsberg: "Re: Help w/ matching grep and regular expressions"
- Reply: Nick Landsberg: "Re: Help w/ matching grep and regular expressions"
- Reply: Alan Connor: "Re: Help w/ matching grep and regular expressions"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|