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 ...
![]() |
| | LinkBack | Thread Tools | Display Modes |
|
#1
| |||
| |||
| 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. |
|
#2
| |||
| |||
|
On May 2, 4:22*pm, Ryan > 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 your example finds everything and runs grep on it????? |
|
#3
| |||
| |||
|
On May 2, 4:41*pm, OldSchool > On May 2, 4:22*pm, Ryan > > > 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 > > your example finds everything and runs grep on it????? This is within a certain directory |
|
#4
| |||
| |||
| On 5/2/2008 3:47 PM, Ryan wrote: > On May 2, 4:41 pm, OldSchool > >>On May 2, 4:22 pm, Ryan >> >> >>>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 >> >>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. |
|
#5
| |||
| |||
|
On May 2, 4:56*pm, Ed Morton > On 5/2/2008 3:47 PM, Ryan wrote: > > > > > On May 2, 4:41 pm, OldSchool > > >>On May 2, 4:22 pm, Ryan > > >>>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 > > >>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. |
|
#6
| |||
| |||
| On 5/2/2008 4:01 PM, Ryan wrote: > On May 2, 4:56 pm, Ed Morton > >>On 5/2/2008 3:47 PM, Ryan wrote: >> >> >> >> >>>On May 2, 4:41 pm, OldSchool >> >>>>On May 2, 4:22 pm, Ryan >>> >>>>>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 >>> >>>>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 " Ed. |
|
#7
| |||
| |||
|
On May 2, 5:05*pm, Ed Morton > On 5/2/2008 4:01 PM, Ryan wrote: > > > > > On May 2, 4:56 pm, Ed Morton > > >>On 5/2/2008 3:47 PM, Ryan wrote: > > >>>On May 2, 4:41 pm, OldSchool > > >>>>On May 2, 4:22 pm, Ryan > > >>>>>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 > > >>>>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 " > > * * * * Ed. The original might end in a number however the duplicates have had [space]1 added before (.mp3|m4a). |
|
#8
| |||
| |||
| On 5/2/2008 4:08 PM, Ryan wrote: > On May 2, 5:05 pm, Ed Morton > >>On 5/2/2008 4:01 PM, Ryan wrote: >> >> >> >> >>>On May 2, 4:56 pm, Ed Morton >> >>>>On 5/2/2008 3:47 PM, Ryan wrote: >>> >>>>>On May 2, 4:41 pm, OldSchool >>>> >>>>>>On May 2, 4:22 pm, Ryan >>>>> >>>>>>>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 >>>>> >>>>>>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 " >> >> 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 |
|
#9
| |||
| |||
|
On May 2, 5:08*pm, Ryan > On May 2, 5:05*pm, Ed Morton > > > > > On 5/2/2008 4:01 PM, Ryan wrote: > > > > On May 2, 4:56 pm, Ed Morton > > > >>On 5/2/2008 3:47 PM, Ryan wrote: > > > >>>On May 2, 4:41 pm, OldSchool > > > >>>>On May 2, 4:22 pm, Ryan > > > >>>>>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 > > > >>>>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 " > > > * * * * 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 {} \; |
|
#10
| |||
| |||
| On 5/2/2008 4:15 PM, Ryan wrote: > On May 2, 5:08 pm, Ryan > >>On May 2, 5:05 pm, Ed Morton >> >> >> >> >>>On 5/2/2008 4:01 PM, Ryan wrote: >> >>>>On May 2, 4:56 pm, Ed Morton >>> >>>>>On 5/2/2008 3:47 PM, Ryan wrote: >>>> >>>>>>On May 2, 4:41 pm, OldSchool >>>>> >>>>>>>On May 2, 4:22 pm, Ryan >>>>>> >>>>>>>>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 >>>>>> >>>>>>>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 " >> >>> 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 :-). |
![]() |
« Previous Thread
|
Next Thread »
| Thread Tools | |
| Display Modes | |
| |
All times are GMT -4. The time now is 11:51 AM.




Linear Mode