PHWinfo banniere

Titres
PORTAIL ANNUAIRE ARTICLES COMPARATEUR HÉBERGEURS DEVIS FORUMS RÉDUCTEUR D'URL
Précédent   PHWinfo > Forums Hébergement > Forum Serveur - Sécurité et techniques > comp.unix.shell > Trouble with grep
S'inscrire FAQ Membres Recherche Messages du jour Marquer les forums comme lus
comp.unix.shell Using and programming the Unix shell.

Trouble with grep

Réponse
 
LinkBack Outils de la discussion
Vieux 02/05/2008, 21h22   #1
Ryan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Trouble with grep

This is driving me nuts i am trying to use the following:

find . -exec grep -l "[0-9]\+\." '{}' \;

to find all files that have a number before a "."

It matches both somefile_ 1.mp3 AND somefile_ .mp3.

Why is this and can you suggest a better pattern? I a=only want to
match the first result above.
  Réponse avec citation
Vieux 02/05/2008, 21h41   #2
OldSchool
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 4:22pm, Ryan <ryan.fairch...@gmail.com> wrote:
> This is driving me nuts i am trying to use the following:
>
> find . -exec grep -l "[0-9]\+\." '{}' \;
>
> to find all files that have a number before a "."
>
> It matches both somefile_ 1.mp3 AND somefile_ .mp3.
>
> Why is this and can you suggest a better pattern? I a=only want to
> match the first result above.


find <path> -name '*[0-9]\.*]

your example finds everything and runs grep on it?????
  Réponse avec citation
Vieux 02/05/2008, 21h47   #3
Ryan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 4:41pm, OldSchool <scott.my...@macys.com> wrote:
> On May 2, 4:22pm, Ryan <ryan.fairch...@gmail.com> wrote:
>
> > This is driving me nuts i am trying to use the following:

>
> > find . -exec grep -l "[0-9]\+\." '{}' \;

>
> > to find all files that have a number before a "."

>
> > It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>
> > Why is this and can you suggest a better pattern? I a=only want to
> > match the first result above.

>
> find <path> -name '*[0-9]\.*]
>
> your example finds everything and runs grep on it?????


This is within a certain directory
  Réponse avec citation
Vieux 02/05/2008, 21h56   #4
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep



On 5/2/2008 3:47 PM, Ryan wrote:
> On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:
>
>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>>
>>
>>>This is driving me nuts i am trying to use the following:

>>
>>>find . -exec grep -l "[0-9]\+\." '{}' \;

>>
>>> to find all files that have a number before a "."

>>
>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>>
>>>Why is this and can you suggest a better pattern? I a=only want to
>>>match the first result above.

>>
>>find <path> -name '*[0-9]\.*]
>>
>>your example finds everything and runs grep on it?????

>
>
> This is within a certain directory


Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
do with matching sub-directories and/or your other requirements.

Ed.

  Réponse avec citation
Vieux 02/05/2008, 22h01   #5
Ryan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 4:56pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 5/2/2008 3:47 PM, Ryan wrote:
>
>
>
> > On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:

>
> >>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:

>
> >>>This is driving me nuts i am trying to use the following:

>
> >>>find . -exec grep -l "[0-9]\+\." '{}' \;

>
> >>> to find all files that have a number before a "."

>
> >>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>
> >>>Why is this and can you suggest a better pattern? I a=only want to
> >>>match the first result above.

>
> >>find <path> -name '*[0-9]\.*]

>
> >>your example finds everything and runs grep on it?????

>
> > This is within a certain directory

>
> Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
> do with matching sub-directories and/or your other requirements.
>
> Ed.


Maybe I should explain the ultimate outcome here. I have a bunch of
duplicate mp3 files that all follow "song 1.mp3", originals are of the
forms "song.mp3". I simply want to find them and delete them. Am I
in the right direction here.
  Réponse avec citation
Vieux 02/05/2008, 22h05   #6
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep



On 5/2/2008 4:01 PM, Ryan wrote:
> On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>On 5/2/2008 3:47 PM, Ryan wrote:
>>
>>
>>
>>
>>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:

>>
>>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>>>
>>>>>This is driving me nuts i am trying to use the following:
>>>>
>>>>>find . -exec grep -l "[0-9]\+\." '{}' \;
>>>>
>>>>>to find all files that have a number before a "."
>>>>
>>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.
>>>>
>>>>>Why is this and can you suggest a better pattern? I a=only want to
>>>>>match the first result above.
>>>>
>>>>find <path> -name '*[0-9]\.*]
>>>
>>>>your example finds everything and runs grep on it?????
>>>
>>>This is within a certain directory

>>
>>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
>>do with matching sub-directories and/or your other requirements.
>>
>> Ed.

>
>
> Maybe I should explain the ultimate outcome here. I have a bunch of
> duplicate mp3 files that all follow "song 1.mp3", originals are of the
> forms "song.mp3". I simply want to find them and delete them. Am I
> in the right direction here.


In the original, can "song" end in a number?

If so, can "song" contain a space before the number?

Do the duplicate files all end in "<space><number[s]>.mp3"?

Ed.

  Réponse avec citation
Vieux 02/05/2008, 22h08   #7
Ryan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 5:05pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
> On 5/2/2008 4:01 PM, Ryan wrote:
>
>
>
> > On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> >>On 5/2/2008 3:47 PM, Ryan wrote:

>
> >>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:

>
> >>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:

>
> >>>>>This is driving me nuts i am trying to use the following:

>
> >>>>>find . -exec grep -l "[0-9]\+\." '{}' \;

>
> >>>>>to find all files that have a number before a "."

>
> >>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>
> >>>>>Why is this and can you suggest a better pattern? I a=only want to
> >>>>>match the first result above.

>
> >>>>find <path> -name '*[0-9]\.*]

>
> >>>>your example finds everything and runs grep on it?????

>
> >>>This is within a certain directory

>
> >>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
> >>do with matching sub-directories and/or your other requirements.

>
> >> Ed.

>
> > Maybe I should explain the ultimate outcome here. I have a bunch of
> > duplicate mp3 files that all follow "song 1.mp3", originals are of the
> > forms "song.mp3". I simply want to find them and delete them. Am I
> > in the right direction here.

>
> In the original, can "song" end in a number?
>
> If so, can "song" contain a space before the number?
>
> Do the duplicate files all end in "<space><number[s]>.mp3"?
>
> Ed.


The original might end in a number however the duplicates have had
[space]1 added before (.mp3|m4a).
  Réponse avec citation
Vieux 02/05/2008, 22h15   #8
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep



On 5/2/2008 4:08 PM, Ryan wrote:
> On May 2, 5:05 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>>On 5/2/2008 4:01 PM, Ryan wrote:
>>
>>
>>
>>
>>>On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>>
>>>>On 5/2/2008 3:47 PM, Ryan wrote:
>>>
>>>>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:
>>>>
>>>>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>>>>>
>>>>>>>This is driving me nuts i am trying to use the following:
>>>>>>
>>>>>>>find . -exec grep -l "[0-9]\+\." '{}' \;
>>>>>>
>>>>>>>to find all files that have a number before a "."
>>>>>>
>>>>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.
>>>>>>
>>>>>>>Why is this and can you suggest a better pattern? I a=only want to
>>>>>>>match the first result above.
>>>>>>
>>>>>>find <path> -name '*[0-9]\.*]
>>>>>
>>>>>>your example finds everything and runs grep on it?????
>>>>>
>>>>>This is within a certain directory
>>>>
>>>>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
>>>>do with matching sub-directories and/or your other requirements.
>>>
>>>> Ed.
>>>
>>>Maybe I should explain the ultimate outcome here. I have a bunch of
>>>duplicate mp3 files that all follow "song 1.mp3", originals are of the
>>>forms "song.mp3". I simply want to find them and delete them. Am I
>>>in the right direction here.

>>
>>In the original, can "song" end in a number?
>>
>>If so, can "song" contain a space before the number?
>>
>>Do the duplicate files all end in "<space><number[s]>.mp3"?
>>
>> Ed.

>
>
> The original might end in a number however the duplicates have had
> [space]1 added before (.mp3|m4a).


Then just do:

ls *\ 1.mp3 *\ 1.m4a

and if you're sure that's the list you want to remove, replace "ls" with "rm".

Ed

  Réponse avec citation
Vieux 02/05/2008, 22h15   #9
Ryan
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 5:08pm, Ryan <ryan.fairch...@gmail.com> wrote:
> On May 2, 5:05pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>
>
>
> > On 5/2/2008 4:01 PM, Ryan wrote:

>
> > > On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> > >>On 5/2/2008 3:47 PM, Ryan wrote:

>
> > >>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:

>
> > >>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:

>
> > >>>>>This is driving me nuts i am trying to use the following:

>
> > >>>>>find . -exec grep -l "[0-9]\+\." '{}' \;

>
> > >>>>>to find all files that have a number before a "."

>
> > >>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>
> > >>>>>Why is this and can you suggest a better pattern? I a=only want to
> > >>>>>match the first result above.

>
> > >>>>find <path> -name '*[0-9]\.*]

>
> > >>>>your example finds everything and runs grep on it?????

>
> > >>>This is within a certain directory

>
> > >>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
> > >>do with matching sub-directories and/or your other requirements.

>
> > >> Ed.

>
> > > Maybe I should explain the ultimate outcome here. I have a bunch of
> > > duplicate mp3 files that all follow "song 1.mp3", originals are of the
> > > forms "song.mp3". I simply want to find them and delete them. AmI
> > > in the right direction here.

>
> > In the original, can "song" end in a number?

>
> > If so, can "song" contain a space before the number?

>
> > Do the duplicate files all end in "<space><number[s]>.mp3"?

>
> > Ed.

>
> The original might end in a number however the duplicates have had
> [space]1 added before (.mp3|m4a).


after banging my head too much i got it.

find . -name '*[0-9]\.*' -exec mv {} </path/to/move/to> \;
  Réponse avec citation
Vieux 02/05/2008, 22h20   #10
Ed Morton
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep



On 5/2/2008 4:15 PM, Ryan wrote:
> On May 2, 5:08 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>
>>On May 2, 5:05 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>>
>>
>>
>>
>>>On 5/2/2008 4:01 PM, Ryan wrote:

>>
>>>>On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:
>>>
>>>>>On 5/2/2008 3:47 PM, Ryan wrote:
>>>>
>>>>>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:
>>>>>
>>>>>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>>>>>>
>>>>>>>>This is driving me nuts i am trying to use the following:
>>>>>>>
>>>>>>>>find . -exec grep -l "[0-9]\+\." '{}' \;
>>>>>>>
>>>>>>>>to find all files that have a number before a "."
>>>>>>>
>>>>>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.
>>>>>>>
>>>>>>>>Why is this and can you suggest a better pattern? I a=only want to
>>>>>>>>match the first result above.
>>>>>>>
>>>>>>>find <path> -name '*[0-9]\.*]
>>>>>>
>>>>>>>your example finds everything and runs grep on it?????
>>>>>>
>>>>>>This is within a certain directory
>>>>>
>>>>>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
>>>>>do with matching sub-directories and/or your other requirements.
>>>>
>>>>> Ed.
>>>>
>>>>Maybe I should explain the ultimate outcome here. I have a bunch of
>>>>duplicate mp3 files that all follow "song 1.mp3", originals are of the
>>>>forms "song.mp3". I simply want to find them and delete them. Am I
>>>>in the right direction here.
>>>
>>>In the original, can "song" end in a number?

>>
>>>If so, can "song" contain a space before the number?

>>
>>>Do the duplicate files all end in "<space><number[s]>.mp3"?

>>
>>> Ed.

>>
>>The original might end in a number however the duplicates have had
>>[space]1 added before (.mp3|m4a).

>
>
> after banging my head too much i got it.
>
> find . -name '*[0-9]\.*' -exec mv {} </path/to/move/to> \;


therein lies the danger of writing scripts after banging your head too much :-).

  Réponse avec citation
Vieux 02/05/2008, 22h57   #11
Javi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 11:15 pm, Ryan <ryan.fairch...@gmail.com> wrote:
> On May 2, 5:08 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>
>
>
> > On May 2, 5:05 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> > > On 5/2/2008 4:01 PM, Ryan wrote:

>
> > > > On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> > > >>On 5/2/2008 3:47 PM, Ryan wrote:

>
> > > >>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:

>
> > > >>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:

>
> > > >>>>>This is driving me nuts i am trying to use the following:

>
> > > >>>>>find . -exec grep -l "[0-9]\+\." '{}' \;

>
> > > >>>>>to find all files that have a number before a "."

>
> > > >>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>
> > > >>>>>Why is this and can you suggest a better pattern? I a=only want to
> > > >>>>>match the first result above.

>
> > > >>>>find <path> -name '*[0-9]\.*]

>
> > > >>>>your example finds everything and runs grep on it?????

>
> > > >>>This is within a certain directory

>
> > > >>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
> > > >>do with matching sub-directories and/or your other requirements.

>
> > > >> Ed.

>
> > > > Maybe I should explain the ultimate outcome here. I have a bunch of
> > > > duplicate mp3 files that all follow "song 1.mp3", originals are of the
> > > > forms "song.mp3". I simply want to find them and delete them. Am I
> > > > in the right direction here.

>
> > > In the original, can "song" end in a number?

>
> > > If so, can "song" contain a space before the number?

>
> > > Do the duplicate files all end in "<space><number[s]>.mp3"?

>
> > > Ed.

>
> > The original might end in a number however the duplicates have had
> > [space]1 added before (.mp3|m4a).

>
> after banging my head too much i got it.
>
> find . -name '*[0-9]\.*' -exec mv {} </path/to/move/to> \;


I think you don't need "\." because -name options wants a pattern and
not a regular expression.

find . -name "* 1.???"
  Réponse avec citation
Vieux 02/05/2008, 22h58   #12
Javi
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On May 2, 11:57 pm, Javi <javibarr...@gmail.com> wrote:
> On May 2, 11:15 pm, Ryan <ryan.fairch...@gmail.com> wrote:
>
>
>
> > On May 2, 5:08 pm, Ryan <ryan.fairch...@gmail.com> wrote:

>
> > > On May 2, 5:05 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> > > > On 5/2/2008 4:01 PM, Ryan wrote:

>
> > > > > On May 2, 4:56 pm, Ed Morton <mor...@lsupcaemnt.com> wrote:

>
> > > > >>On 5/2/2008 3:47 PM, Ryan wrote:

>
> > > > >>>On May 2, 4:41 pm, OldSchool <scott.my...@macys.com> wrote:

>
> > > > >>>>On May 2, 4:22 pm, Ryan <ryan.fairch...@gmail.com> wrote:

>
> > > > >>>>>This is driving me nuts i am trying to use the following:

>
> > > > >>>>>find . -exec grep -l "[0-9]\+\." '{}' \;

>
> > > > >>>>>to find all files that have a number before a "."

>
> > > > >>>>>It matches both somefile_ 1.mp3 AND somefile_ .mp3.

>
> > > > >>>>>Why is this and can you suggest a better pattern? I a=only want to
> > > > >>>>>match the first result above.

>
> > > > >>>>find <path> -name '*[0-9]\.*]

>
> > > > >>>>your example finds everything and runs grep on it?????

>
> > > > >>>This is within a certain directory

>
> > > > >>Then add "-maxdepth 1", or use "ls" instead of "find". Depends what you want to
> > > > >>do with matching sub-directories and/or your other requirements.

>
> > > > >> Ed.

>
> > > > > Maybe I should explain the ultimate outcome here. I have a bunch of
> > > > > duplicate mp3 files that all follow "song 1.mp3", originals are of the
> > > > > forms "song.mp3". I simply want to find them and delete them. Am I
> > > > > in the right direction here.

>
> > > > In the original, can "song" end in a number?

>
> > > > If so, can "song" contain a space before the number?

>
> > > > Do the duplicate files all end in "<space><number[s]>.mp3"?

>
> > > > Ed.

>
> > > The original might end in a number however the duplicates have had
> > > [space]1 added before (.mp3|m4a).

>
> > after banging my head too much i got it.

>
> > find . -name '*[0-9]\.*' -exec mv {} </path/to/move/to> \;

>
> I think you don't need "\." because -name options wants a pattern and
> not a regular expression.
>
> find . -name "* 1.???"


Sorry
find . -name "* [1-9].???"
  Réponse avec citation
Vieux 03/05/2008, 11h45   #13
Dave B
Aucun Avatar
 
Messages: n/a
Hébergeur:
Par défaut Re: Trouble with grep

On Friday 2 May 2008 22:22, Ryan wrote:

> This is driving me nuts i am trying to use the following:
>
> find . -exec grep -l "[0-9]\+\." '{}' \;
>
> to find all files that have a number before a "."
>
> It matches both somefile_ 1.mp3 AND somefile_ .mp3.


Your command looks for the regular expression "[0-9]\+\." *inside* the
files, not in their names.

--
D.
  Réponse avec citation
Réponse


Outils de la discussion

Règles de messages
Vous ne pouvez pas créer de nouvelles discussions
Vous ne pouvez pas envoyer des réponses
Vous ne pouvez pas envoyer des pièces jointes
Vous ne pouvez pas modifier vos messages

Les balises BB sont activées : oui
Les smileys sont activés : oui
La balise [IMG] est activée : oui
Le code HTML peut être employé : non
Trackbacks are oui
Pingbacks are oui
Refbacks are oui


Fuseau horaire GMT +1. Il est actuellement 13h35.


Édité par : vBulletin® version 3.7.3
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC5 Tous droits réservés.
Version française #16 par l'association vBulletin francophone
PHWinfo est un site Éducation Sans Frontières ©2000-2008
Ad Management by RedTyger
©Tous droits réservés par les parties respectives
Page generated in 0,28665 seconds with 21 queries