use grep's --null option in combination with xargs -0 option:

ls | grep -i foobar --null | xargs -0 mv %1 /newdir

A few other commands have options for using null separators.  eg

find -print0
perl -0

Thing is, a lot of the time what you want is to use the input you've
already got which is argument per line, as in the output from ls.  I used
to have a little script around called lxargs which wrapped xargs and
replaced line ends with nulls on stdin.  I've misplaced it but should
really re-implement it.

Andrew





On Sat, 9 Aug 2003, Joel Heenan wrote:

> Hello Sluggers!
>
> I am often moving or coping files with spaces in them. What I would really
> like is be able to get just go
>
> | xargs mv %1 /newdir
>
> or something similar. At the moment I am stuck writing scripts like this
>
> #!/bin/bash
> IFS='
> '
> for f in `/bin/ls | grep -i $1`
> do
>         mv -v "$f" $2
> done
>
> What I would like is a general solution where I can say execute this command
> on every line in this file. Should I extend this script so it takes in the
> "mv -v" script on command line and works off standard input or is there an
> easier/better way? Surely this is a simple problem but I can't see the
> simple solution. :-(
>
> Joel
>
>

--

No added Sugar.  Not tested on animals.  May contain traces of Nuts.  If
irritation occurs, discontinue use.

-------------------------------------------------------------------
Andrew McNaughton           In Sydney
                            Working on a Product Recommender System
[EMAIL PROTECTED]
Mobile: +61 422 753 792     http://staff.scoop.co.nz/andrew/cv.doc



-- 
SLUG - Sydney Linux User's Group - http://slug.org.au/
More Info: http://lists.slug.org.au/listinfo/slug

Reply via email to