Re: grep, maybe

2009-10-29 Thread Joshua Judson Rosen
Ben Scott  writes:
>
> On Thu, Oct 29, 2009 at 2:20 PM, Joshua Judson Rosen
>  wrote:
> >
> > Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr.
> 
>   Okay, I'll ask: What does that stuff to the right mean?

The other half of the whole habanero pepper. :)

More lucidly: a combinator. ;)

It's a pun. Actually, somehow this never occurred to me before, but
since the sentence as a whole is `an imperative', and the `question'
to be asked is functional, I guess it's... a functional imperative? So
maybe it's a deeper (or worse) joke than I originally intended

> Some kind of LISP?

Almost. Did you have any luck googling for it? :)

-- 
Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr.
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Remember your pearls [was grep, maybe]

2009-10-29 Thread Greg Rundlett (freephile)
Not an answer to the OP, but a follow-on.

So, you've worked out a magnificent one-liner solution to a
interesting and recurring task.  How do you 'remember' your solution?

Do you create a file with scripts and comments?
Do you post it in a wiki?
A blog?
An IDE with snippets?
Do you remember it in your head?

I used to store my good one-liners in Konsole as 'bookmarks' because
you could put anything into a bookmark. Until KDE4. They "improved"
the bookmark system which now only knows telnet:// and ssh:// "URLs".
Konsole even re-writes your bookmarks as you save them by url-encoding
them.  The issue is apparently due to reliance on Kurl - a core class
in KDE, and so "not a problem" with Konsole.

http://bugs.kde.org/show_bug.cgi?id=185962
http://bugs.kde.org/show_bug.cgi?id=88867

Greg Rundlett

nbpt 978-225-8302
m. 978-764-4424
-skype/aim/irc/twitter freephile
http://profiles.aim.com/freephile
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Ken D'Ambrosio
Wups!  Sorry -- I read your question wrong: "Does *find* run
concurrently*.  I'd had other concerns, and mis-read your question to fit
my thinking.  D'oh!  It's been my experience that find doesn't get
confused, it just gets miffed, and moves on.

-Ken

On Thu, October 29, 2009 5:03 pm, Ken D'Ambrosio wrote:
> Interesting point.  Three replies:
> 1) If you're mv'ing onto the same filesystem, the inodes will never
> change, and it won't matter. 2) I imagine grep will only spit out a status
> (which is what the "&&"
> parses) after it's finished running, though I'd have to verify that
> empirically. 3) You can cheat, and do something like this:
>
>
> cat "$i/*" | grep -l moe && mv "$i" /destpath || echo "mv didn't work:
> $?"
>
>
> -Ken
>
>
> On Thu, October 29, 2009 4:41 pm, Ben Scott wrote:
>
>> On Thu, Oct 29, 2009 at 2:31 PM, Ken D'Ambrosio  wrote:
>>
>>
>>> find -type d | while read i do grep moe "$i/*" && mv "$i"
>>> /path/to/destination || echo "mv didn't work: $?"
>>> done
>>
>> Hmmm, does the "find" execute concurrently with the "grep"?  If it
>> does, then you're liable to confuse the hell out of "find" if you manage
>> to move a directory which is a component of the path it's currently
>> trasversing.
>>
>> -- Ben
>> ___
>> gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org
>> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>>
>>
>>
>> --
>> This message has been scanned for viruses and
>> dangerous content by MailScanner, and is believed to be clean.
>>
>>
>
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is believed to be clean.
>
> ___
> gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>
>



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Ken D'Ambrosio
Interesting point.  Three replies:
1) If you're mv'ing onto the same filesystem, the inodes will never
change, and it won't matter.
2) I imagine grep will only spit out a status (which is what the "&&"
parses) after it's finished running, though I'd have to verify that
empirically.
3) You can cheat, and do something like this:

cat "$i/*" | grep -l moe && mv "$i" /destpath || echo "mv didn't work: $?"

-Ken

On Thu, October 29, 2009 4:41 pm, Ben Scott wrote:
> On Thu, Oct 29, 2009 at 2:31 PM, Ken D'Ambrosio  wrote:
>
>> find -type d | while read i do grep moe "$i/*" && mv "$i"
>> /path/to/destination || echo "mv didn't work: $?"
>> done
>
> Hmmm, does the "find" execute concurrently with the "grep"?  If it
> does, then you're liable to confuse the hell out of "find" if you manage to
> move a directory which is a component of the path it's currently
> trasversing.
>
> -- Ben
> ___
> gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is believed to be clean.
>
>



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Ben Scott
On Thu, Oct 29, 2009 at 2:20 PM, Joshua Judson Rosen
 wrote:

>    grep --recursive --files-with-matches "$searchstring" "$topdir" \
>    | xargs --max-args=1 dirname \
>    | sort --unique \
>    | xargs mv --target-directory="$newloc"

  I like it.  I didn't know about the "--target-directory" option to
mv(1).  That'll come in handy in the future.  Thanks...

  Hmmm, file names with spaces are likely to foul things; xargs splits
on any whitespace by default.  Maybe:

grep --recursive --files-with-matches "$searchstring" "$topdir" \
| xargs --delimiter=\\n --max-args=1 dirname \
| sort --unique \
| xargs --delimiter=\\n mv --target-directory="$newloc"

  Explicitly specifying the delimiter as newline means "newline only".
 Whitespace within a line is ignored.

  (It will still fail if a file name contains a *newline*, but that's
pathological, while file names with spaces are quite common.)

> Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr.

  Okay, I'll ask: What does that stuff to the right mean?  Some kind of LISP?

-- Ben

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Ben Scott
On Thu, Oct 29, 2009 at 2:31 PM, Ken D'Ambrosio  wrote:
> find -type d | while read i
> do
> grep moe "$i/*" && mv "$i" /path/to/destination || echo "mv didn't work: $?"
> done

  Hmmm, does the "find" execute concurrently with the "grep"?  If it
does, then you're liable to confuse the hell out of "find" if you
manage to move a directory which is a component of the path it's
currently trasversing.

-- Ben
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Ken D'Ambrosio
Oooh!  A challenge!  Here's my solution:

#!/bin/sh
cd /path/to/toplevel/dir
find -type d | while read i
do
grep moe "$i/*" && mv "$i" /path/to/destination || echo "mv didn't work: $?"
done

-Ken

On Thu, October 29, 2009 1:31 pm, mark wrote:
> On Thu, Oct 29, 2009 at 11:38 AM, Maurice
> wrote:
>
>
>> Looking for some guidance;
>>
>>
>> I have several files within several folders (5 files per folder, and
>> thousands of folders) that I need to search a text file within each
>> folder for a word match (like three_little_pigs.txt, and I need to find
>>  "moe", if he's listed) and then when a match is found I need to move
>> (not copy) that entire folder (and it's 3~5 files contained within) to
>> another location...
>>
>>
>
> #!/bin/sh
> cd [top level directory] grep -l -r ["search string in double quotes"] >
> /tmp/file_names_found
> 2>/tmp/grep.errs
> cat /tmp/file_names_found|xargs -i basename {} >/tmp/dir_names_to_move
> dir_list=`sort /tmp/dir_names_to_move|unique` for DIRECTORY in
> $("dir_list"); do
> mvdir $DIRECTORY [new location here] STATUS=$?
> if [ $STATUS -ne 0 ]; then echo "mvdir returned status $STATUS" end done
exit
>
> You'll have to come up with a way to create the value for "new location
> here" that is unique so you don't overlay all the directories into the
> same path and lose everything, so maybe test it with a copy first.  You'll
> also want to check /tmp/grep.errs for any error messages.  I hope this
> helps.
>
> mark
>
> --
> This message has been scanned for viruses and
> dangerous content by MailScanner, and is believed to be clean.
>
> ___
> gnhlug-discuss mailing list gnhlug-discuss@mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>
>



-- 
This message has been scanned for viruses and
dangerous content by MailScanner, and is
believed to be clean.

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Joshua Judson Rosen
mark  writes:
>
> On Thu, Oct 29, 2009 at 11:38 AM, Maurice  wrote:
> 
> > Looking for some guidance;
> >
> > I have several files within several folders (5 files per folder, and
> > thousands of folders) that I need to search a text file within each
> > folder for a word match (like three_little_pigs.txt, and I need to find
> > "moe", if he's listed) and then when a match is found I need to move
> > (not copy) that entire folder (and it's 3~5 files contained within) to
> > another location...
> 
> #!/bin/sh
> cd [top level directory]
> grep -l -r ["search string in double quotes"] > /tmp/file_names_found  2>/tmp/
> grep.errs
> cat /tmp/file_names_found|xargs -i basename {} >/tmp/dir_names_to_move
> dir_list=`sort /tmp/dir_names_to_move|unique`
> for DIRECTORY in $("dir_list"); do
>  mvdir $DIRECTORY [new location here]
>  STATUS=$?
>  if [ $STATUS -ne 0 ]; then
>     echo "mvdir returned status $STATUS"
>  end
> done
> exit


I'd probably go with something like:

grep --recursive --files-with-matches "$searchstring" "$topdir" \
| xargs --max-args=1 dirname \
| sort --unique \
| xargs mv --target-directory="$newloc"

The only thing that really sucks about that is that the involvement of
`sort' means that the mv needs to wait until *all* of the files have
been grep'd, instead of just moving the directory as soon as *any*
file in it is found to contain the search-term.

And, depending on whether your directories vary in the depth of their
nesting, and whether you prefer to move the more- or less-deep
directories first (or at all), you may need to add a "--reverse" to
the `sort' line or do more complicated filtering with an additional
grep (on the *paths*) or sed.

-- 
Don't be afraid to ask (Lf.((Lx.xx) (Lr.f(rr.

___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread mark
On Thu, Oct 29, 2009 at 11:38 AM, Maurice wrote:

> Looking for some guidance;
>
> I have several files within several folders (5 files per folder, and
> thousands of folders) that I need to search a text file within each
> folder for a word match (like three_little_pigs.txt, and I need to find
> "moe", if he's listed) and then when a match is found I need to move
> (not copy) that entire folder (and it's 3~5 files contained within) to
> another location...
>
>

#!/bin/sh
cd [top level directory]
grep -l -r ["search string in double quotes"] > /tmp/file_names_found
2>/tmp/grep.errs
cat /tmp/file_names_found|xargs -i basename {} >/tmp/dir_names_to_move
dir_list=`sort /tmp/dir_names_to_move|unique`
for DIRECTORY in $("dir_list"); do
 mvdir $DIRECTORY [new location here]
 STATUS=$?
 if [ $STATUS -ne 0 ]; then
echo "mvdir returned status $STATUS"
 end
done
exit

You'll have to come up with a way to create the value for "new location
here" that is unique so you don't overlay all the directories into the same
path and lose everything, so maybe test it with a copy first.  You'll also
want to check /tmp/grep.errs for any error messages.  I hope this helps.

mark
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Ben Scott
On Thu, Oct 29, 2009 at 11:38 AM, Maurice  wrote:
> I need to search a text file within each
> folder for a word match (like three_little_pigs.txt, and I need to find
> "moe", if he's listed) and then when a match is found I need to move
> (not copy) that entire folder (and it's 3~5 files contained within) to
> another location...

  Well, the following will search for any file containing "moe"
(exactly), and list matching files:

grep -l -r moe /path/to/top/level/directory

  If you want a case-insensitive search (match "moe", "Moe", "MoE", etc.):

grep -i -l -r moe /path/to/top/level/directory

  If you want to search for multiple names, separate them by vertical
bars (|).  You will have to quote the search string to keep the bars
from being interpreted by the shell:

grep -i -l -r 'moe|larry|curly' /path/to/top/level/directory

  Moving just the files would be pretty easy.  Moving the
*directories* would be trickier.  We can't move it when grep is still
in the directory, so we'll have to save a list somewhere, then parse
the list to find the directory names, then eliminate the duplicates,
then move the directories.

-- Ben
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


Re: grep, maybe

2009-10-29 Thread Drew Van Zandt
grep -r greps all files recursively.
grep -l outputs only the names of files which contain matching text.

To move the folders, you would have to process that output to select the
directory, then move the directory.  Probably a perl or shell scripting
task.

AFAIK grep has nothing so specific as moving the folders the files are in,
but it gets you 80% of the way there.

--DTVZ

On Thu, Oct 29, 2009 at 11:38 AM, Maurice wrote:

> Looking for some guidance;
>
> I have several files within several folders (5 files per folder, and
> thousands of folders) that I need to search a text file within each
> folder for a word match (like three_little_pigs.txt, and I need to find
> "moe", if he's listed) and then when a match is found I need to move
> (not copy) that entire folder (and it's 3~5 files contained within) to
> another location...
>
> I'm thinking grep, but don't know the correct syntax to make all this
> happen.
> I can easily find all the folders (1949 of them) and the word match 3923
> times within the text file(s)...
>
>
> Any ideas???
>
>
>
> --
> -Maurice Pelletier
> Child Development Services - Cumberland County
> 50 Depot Road
> Falmouth, ME 04105
> 207-781-8881 (voice)
> 207-781-8855 (fax)
>
> www.cds-cumberland.org
>
>
> "Linux -- it's not just for breakfast anymore..."
> -Moe
>
>
>
> ___
> gnhlug-discuss mailing list
> gnhlug-discuss@mail.gnhlug.org
> http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/
>
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


grep, maybe

2009-10-29 Thread Maurice
Looking for some guidance;

I have several files within several folders (5 files per folder, and 
thousands of folders) that I need to search a text file within each 
folder for a word match (like three_little_pigs.txt, and I need to find 
"moe", if he's listed) and then when a match is found I need to move 
(not copy) that entire folder (and it's 3~5 files contained within) to 
another location...

I'm thinking grep, but don't know the correct syntax to make all this 
happen.
I can easily find all the folders (1949 of them) and the word match 3923 
times within the text file(s)...


Any ideas???



-- 
-Maurice Pelletier
Child Development Services - Cumberland County
50 Depot Road
Falmouth, ME 04105
207-781-8881 (voice)
207-781-8855 (fax)

www.cds-cumberland.org


"Linux -- it's not just for breakfast anymore..."
-Moe



___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/


landscape architecture software

2009-10-29 Thread Greg Rundlett (freephile)
I wanted to do some modelling of my home landscaping.  Anyone know of
an application that does this (Linux-compatible of course)?

There are many software packages available for Windows, but I can't
seem to find any that are linux compatible.  I thought to try my hand
at using Blender, but I'd really like to use something that is
specifically pre-tooled to deal with landscaping.  For example the
commercial Windows packages have thousands of photorealistic plants
and things that you can add to your models.

Greg Rundlett

nbpt 978-225-8302
m. 978-764-4424
-skype/aim/irc/twitter freephile
http://profiles.aim.com/freephile
___
gnhlug-discuss mailing list
gnhlug-discuss@mail.gnhlug.org
http://mail.gnhlug.org/mailman/listinfo/gnhlug-discuss/