grep, maybe

Ben Scott dragonhawk at gmail.com
Thu Oct 29 16:55:54 EDT 2009


On Thu, Oct 29, 2009 at 2:20 PM, Joshua Judson Rosen
<rozzin at geekspace.com> 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



More information about the gnhlug-discuss mailing list