dbaspot
Tags Register FAQ Calendar Search Today's Posts Mark Forums Read

Trouble with grep - shell

This is a discussion on Trouble with grep - shell ; 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 ...


Home > Database Forum > Operating Systems > shell > Trouble with grep

Reply

 

LinkBack Thread Tools Display Modes
  #1  
Old 05-02-2008, 04:22 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default 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.
Reply With Quote
  #2  
Old 05-02-2008, 04:41 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep

On May 2, 4:22*pm, 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.
>
> Why is this and can you suggest a better pattern? *I a=only want to
> match the first result above.


find -name '*[0-9]\.*]

your example finds everything and runs grep on it?????
Reply With Quote
  #3  
Old 05-02-2008, 04:47 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep

On May 2, 4:41*pm, OldSchool wrote:
> On May 2, 4:22*pm, 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.

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

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


This is within a certain directory
Reply With Quote
  #4  
Old 05-02-2008, 04:56 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep



On 5/2/2008 3:47 PM, Ryan wrote:
> On May 2, 4:41 pm, OldSchool wrote:
>
>>On May 2, 4:22 pm, 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.

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

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

Reply With Quote
  #5  
Old 05-02-2008, 05:01 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep

On May 2, 4:56*pm, Ed Morton wrote:
> On 5/2/2008 3:47 PM, Ryan wrote:
>
>
>
> > On May 2, 4:41 pm, OldSchool wrote:

>
> >>On May 2, 4:22 pm, 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.

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

>
> >>find -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.
Reply With Quote
  #6  
Old 05-02-2008, 05:05 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep



On 5/2/2008 4:01 PM, Ryan wrote:
> On May 2, 4:56 pm, Ed Morton wrote:
>
>>On 5/2/2008 3:47 PM, Ryan wrote:
>>
>>
>>
>>
>>>On May 2, 4:41 pm, OldSchool wrote:

>>
>>>>On May 2, 4:22 pm, 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.
>>>>
>>>>>Why is this and can you suggest a better pattern? I a=only want to
>>>>>match the first result above.
>>>>
>>>>find -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 ".mp3"?

Ed.

Reply With Quote
  #7  
Old 05-02-2008, 05:08 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep

On May 2, 5:05*pm, Ed Morton wrote:
> On 5/2/2008 4:01 PM, Ryan wrote:
>
>
>
> > On May 2, 4:56 pm, Ed Morton wrote:

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

>
> >>>On May 2, 4:41 pm, OldSchool wrote:

>
> >>>>On May 2, 4:22 pm, 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.

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

>
> >>>>find -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 ".mp3"?
>
> * * * * Ed.


The original might end in a number however the duplicates have had
[space]1 added before (.mp3|m4a).
Reply With Quote
  #8  
Old 05-02-2008, 05:15 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep



On 5/2/2008 4:08 PM, Ryan wrote:
> On May 2, 5:05 pm, Ed Morton wrote:
>
>>On 5/2/2008 4:01 PM, Ryan wrote:
>>
>>
>>
>>
>>>On May 2, 4:56 pm, Ed Morton wrote:

>>
>>>>On 5/2/2008 3:47 PM, Ryan wrote:
>>>
>>>>>On May 2, 4:41 pm, OldSchool wrote:
>>>>
>>>>>>On May 2, 4:22 pm, 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.
>>>>>>
>>>>>>>Why is this and can you suggest a better pattern? I a=only want to
>>>>>>>match the first result above.
>>>>>>
>>>>>>find -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 ".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

Reply With Quote
  #9  
Old 05-02-2008, 05:15 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep

On May 2, 5:08*pm, Ryan wrote:
> On May 2, 5:05*pm, Ed Morton wrote:
>
>
>
> > On 5/2/2008 4:01 PM, Ryan wrote:

>
> > > On May 2, 4:56 pm, Ed Morton wrote:

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

>
> > >>>On May 2, 4:41 pm, OldSchool wrote:

>
> > >>>>On May 2, 4:22 pm, 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.

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

>
> > >>>>find -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 ".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 {} \;
Reply With Quote
  #10  
Old 05-02-2008, 05:20 PM
Database Bot
 
Join Date: Sep 2009
Posts: 1,236,254
Database Administrator is on a distinguished road
Default Re: Trouble with grep



On 5/2/2008 4:15 PM, Ryan wrote:
> On May 2, 5:08 pm, Ryan wrote:
>
>>On May 2, 5:05 pm, Ed Morton wrote:
>>
>>
>>
>>
>>>On 5/2/2008 4:01 PM, Ryan wrote:

>>
>>>>On May 2, 4:56 pm, Ed Morton wrote:
>>>
>>>>>On 5/2/2008 3:47 PM, Ryan wrote:
>>>>
>>>>>>On May 2, 4:41 pm, OldSchool wrote:
>>>>>
>>>>>>>On May 2, 4:22 pm, 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.
>>>>>>>
>>>>>>>>Why is this and can you suggest a better pattern? I a=only want to
>>>>>>>>match the first result above.
>>>>>>>
>>>>>>>find -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 ".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 {} \;


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

Reply With Quote
Reply

Thread Tools
Display Modes



All times are GMT -4. The time now is 11:51 AM.