APM: Modify in place and Argument list too long

Mike Stok mike at stok.co.uk
Mon Mar 17 13:17:26 CST 2003


On Mon, 17 Mar 2003, Wayne Walker wrote:

> On Mon, Mar 17, 2003 at 12:57:34PM -0600, David Bluestein II wrote:
> > I'm doing a perl modify in place for a directory full of html files, yet I
> > have several directories which have too many files for this:
> > 
> > bash# perl -pi -e 's/oldtext/newtext/g' *html
> > bash: /bin/perl: Argument list too long
> 
> ls | grep '\.html$' | xargs perl -pi -e 's/oldtext/newtext/g'
> 
> xargs is part of the "find" package.  Arg list too long comes from the
> kernel settings and can't be easily changed.  xargs takes __words__ on
> standard input and makes them arguments and passes then to as many
> invocations of the program as needed.

The only thing I would add is that you can use find and xargs together on 
files whose names include blanks, tabs, newlines etc like this

[mike at ratdog tmp]$ touch foo.html
[mike at ratdog tmp]$ touch 'bar baz.html'
[mike at ratdog tmp]$ ls -l
total 0
-rw-rw-r--    1 mike     mike            0 Mar 17 14:15 bar baz.html
-rw-rw-r--    1 mike     mike            0 Mar 17 14:15 foo.html
[mike at ratdog tmp]$ find . -name '*.html' | xargs ls
ls: ./bar: No such file or directory
ls: baz.html: No such file or directory
./foo.html
[mike at ratdog tmp]$ find . -name '*.html' -print0 | xargs -0 ls
./bar baz.html  ./foo.html

Mike

-- 
mike at stok.co.uk                    |           The "`Stok' disclaimers" apply.
http://www.stok.co.uk/~mike/       | GPG PGP Key      1024D/059913DA 
mike at exegenix.com                  | Fingerprint      0570 71CD 6790 7C28 3D60
http://www.exegenix.com/           |                  75D2 9EC4 C1C0 0599 13DA




More information about the Austin mailing list