* 'mv' all files containing a certain string to a sub-directory
@ 2006-10-31 12:59 zzapper
2006-10-31 13:25 ` Heinrich Götzger
` (2 more replies)
0 siblings, 3 replies; 8+ messages in thread
From: zzapper @ 2006-10-31 12:59 UTC (permalink / raw)
To: zsh-users
Hi
I want to 'mv' all files containing a certain string to a sub-directory.
Should be trivial but cant think how w/o creating a temporary file
--
http://successtheory.com/tips/ Vim, Zsh, MySQL Tips
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 12:59 'mv' all files containing a certain string to a sub-directory zzapper
@ 2006-10-31 13:25 ` Heinrich Götzger
2006-10-31 13:40 ` Matt Wozniski
2006-10-31 14:12 ` Jean-Rene David
2006-10-31 14:19 ` Peter Stephenson
2 siblings, 1 reply; 8+ messages in thread
From: Heinrich Götzger @ 2006-10-31 13:25 UTC (permalink / raw)
To: zsh-users
zzapper wrote:
> Hi
> I want to 'mv' all files containing a certain string to a sub-directory.
> Should be trivial but cant think how w/o creating a temporary file
>
>
>
Are you looking for smth like:
find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
HTH
Heinrich
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 13:25 ` Heinrich Götzger
@ 2006-10-31 13:40 ` Matt Wozniski
2006-10-31 13:59 ` Heinrich Götzger
0 siblings, 1 reply; 8+ messages in thread
From: Matt Wozniski @ 2006-10-31 13:40 UTC (permalink / raw)
To: zsh-users
> Are you looking for smth like:
>
> find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
>
> HTH
Heinrich's suggestion would move files both in the current directory
and subdirectories that match your search string. If you only want
the current directory, you should be fine to use a
mv *somestring* tmp
~Matt
PS - Sorry Heinrich, I accidentally sent this to you instead of the
list at first. My bad. :)
On 10/31/06, Heinrich Götzger <goetzger@gmx.de> wrote:
> zzapper wrote:
> > Hi
> > I want to 'mv' all files containing a certain string to a sub-directory.
> > Should be trivial but cant think how w/o creating a temporary file
> >
> >
> >
>
> Are you looking for smth like:
>
> find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
>
> HTH
>
> Heinrich
>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 13:40 ` Matt Wozniski
@ 2006-10-31 13:59 ` Heinrich Götzger
0 siblings, 0 replies; 8+ messages in thread
From: Heinrich Götzger @ 2006-10-31 13:59 UTC (permalink / raw)
To: zsh-users
Matt,
Matt Wozniski wrote:
>> Are you looking for smth like:
>>
>> find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
>>
>> HTH
>
> Heinrich's suggestion would move files both in the current directory
> and subdirectories that match your search string. If you only want
> the current directory, you should be fine to use a
>
> mv *somestring* tmp
this moves all files containig 'somestring' in it's filename, not in the
file itself, as I understood it and as it would in the former command.
But you are right, the find expressens prerequisite would be that it is
not allowd to have 2 or more files matching the grep with the same name
in different directories in '.'. Otherwise you would sould only find a
subset of files in tmp
And tmp should not be a subdirectory of the directory you are searching
in it would break with an error for moving the same file to itself
>
> ~Matt
>
> PS - Sorry Heinrich, I accidentally sent this to you instead of the
> list at first. My bad. :)
don't worry, happend to me 10 Minutes ago as well :-)
cheers
Heinrich
>
> On 10/31/06, Heinrich Götzger <goetzger@gmx.de> wrote:
>> zzapper wrote:
>> > Hi
>> > I want to 'mv' all files containing a certain string to a
>> sub-directory.
>> > Should be trivial but cant think how w/o creating a temporary file
>> >
>> >
>> >
>>
>> Are you looking for smth like:
>>
>> find . -type f -exec grep -e "a certain string" {} \; -exec mv {} tmp \;
>>
>> HTH
>>
>> Heinrich
>>
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 12:59 'mv' all files containing a certain string to a sub-directory zzapper
2006-10-31 13:25 ` Heinrich Götzger
@ 2006-10-31 14:12 ` Jean-Rene David
2006-10-31 14:19 ` Peter Stephenson
2 siblings, 0 replies; 8+ messages in thread
From: Jean-Rene David @ 2006-10-31 14:12 UTC (permalink / raw)
To: zsh-users
On Tue, Oct 31, 2006 at 12:59:15PM +0000, zzapper wrote:
> I want to 'mv' all files containing a certain
> string to a sub-directory. Should be trivial
> but cant think how w/o creating a temporary file
For non-recursive behavior:
for file in *; do
grep -q "somestring" "$file" && mv "$file" "somedir"
done
Recursive behavior is more tricky, as mentioned
elsewhere in this thread.
--
JR
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 12:59 'mv' all files containing a certain string to a sub-directory zzapper
2006-10-31 13:25 ` Heinrich Götzger
2006-10-31 14:12 ` Jean-Rene David
@ 2006-10-31 14:19 ` Peter Stephenson
2006-10-31 15:32 ` zzapper
2 siblings, 1 reply; 8+ messages in thread
From: Peter Stephenson @ 2006-10-31 14:19 UTC (permalink / raw)
To: zsh-users
zzapper wrote:
> I want to 'mv' all files containing a certain string to a sub-directory.
> Should be trivial but cant think how w/o creating a temporary file
mv *(.e:'grep -q string $REPLY':) subdir
--
Peter Stephenson <pws@csr.com> Software Engineer
CSR PLC, Churchill House, Cambridge Business Park, Cowley Road
Cambridge, CB4 0WZ, UK Tel: +44 (0)1223 692070
To access the latest news from CSR copy this link into a web browser: http://www.csr.com/email_sig.php
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 14:19 ` Peter Stephenson
@ 2006-10-31 15:32 ` zzapper
2006-10-31 16:51 ` Nikolai Weibull
0 siblings, 1 reply; 8+ messages in thread
From: zzapper @ 2006-10-31 15:32 UTC (permalink / raw)
To: zsh-users
Peter Stephenson <pws@csr.com> wrote in news:200610311419.k9VEJaKf009817
@news01.csr.com:
> zzapper wrote:
>> I want to 'mv' all files containing a certain string to a sub-directory.
>> Should be trivial but cant think how w/o creating a temporary file
>
> mv *(.e:'grep -q string $REPLY':) subdir
>
Seeing PWS's reply reminded me of the conventional way to do this
mv $(grep -il "userid" *.php) done
--
http://successtheory.com/tips/ Vim, Zsh, MySQL Tips
^ permalink raw reply [flat|nested] 8+ messages in thread
* Re: 'mv' all files containing a certain string to a sub-directory
2006-10-31 15:32 ` zzapper
@ 2006-10-31 16:51 ` Nikolai Weibull
0 siblings, 0 replies; 8+ messages in thread
From: Nikolai Weibull @ 2006-10-31 16:51 UTC (permalink / raw)
To: zzapper; +Cc: zsh-users
On 10/31/06, zzapper <david@tvis.co.uk> wrote:
> Peter Stephenson <pws@csr.com> wrote in news:200610311419.k9VEJaKf009817
> @news01.csr.com:
>
> > zzapper wrote:
> >> I want to 'mv' all files containing a certain string to a sub-directory.
> >> Should be trivial but cant think how w/o creating a temporary file
> >
> > mv *(.e:'grep -q string $REPLY':) subdir
> >
> Seeing PWS's reply reminded me of the conventional way to do this
>
> mv $(grep -il "userid" *.php) done
That doesn't work with files with spaces in them, though.
nikolai
^ permalink raw reply [flat|nested] 8+ messages in thread
end of thread, other threads:[~2006-10-31 16:51 UTC | newest]
Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-10-31 12:59 'mv' all files containing a certain string to a sub-directory zzapper
2006-10-31 13:25 ` Heinrich Götzger
2006-10-31 13:40 ` Matt Wozniski
2006-10-31 13:59 ` Heinrich Götzger
2006-10-31 14:12 ` Jean-Rene David
2006-10-31 14:19 ` Peter Stephenson
2006-10-31 15:32 ` zzapper
2006-10-31 16:51 ` Nikolai Weibull
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/zsh/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).