Automatic way of applying the same command to a bunch of files
Todd Zullinger
tmz at pobox.com
Wed Sep 20 22:36:06 UTC 2006
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Paul Smith wrote:
>>To use the {} replacement for the file, xargs should have the -i
>>option:
>>
>> ... | xargs -0 -i sox '{}' ...
>>
>>Of course, the xargs manpage says that -i is deprecacted and you
>>should instead use -I replace-str. You can make things more
>>readable this way as well:
>>
>> ... | xargs -0 -I wav sox 'wav' ...
>
> It does not work either:
>
> $ find . -name \*.wav -print0 | xargs -0 -I wav sox "{}" -r 44100 -t
> wav "output_{}"
> sox: Can't open input file '{}': No such file or directory
That's because you've used {} instead of wav. The xargs -I option
specifies a replacement string to be used when running the command.
So if you say -I wav, then wav is the replacement string that is used.
The xargs -i option is shorthand for -I {}.
The important thing missing from the original xargs command was -i.
Without that, {} won't have any special significance. I as just
pointing out that the xargs manpage labels -i as deprecated and
recommends the use of -I replace-str.
See the xargs manpage for details.
Of course, I wouldn't even bother with xargs in this case. I'd do
just what Paul Howarth recommended in the beginning of this thread:
for in in *.wav; do sox "$i" -r 44100 "output_$i"; done
- --
Todd OpenPGP -> KeyID: 0xBEAF0CE3 | URL: www.pobox.com/~tmz/pgp
======================================================================
If a government were put in charge of the Sahara Desert, within five
years they'd have a shortage of sand.
-- Dr. Milton Friedman
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (GNU/Linux)
iQFDBAEBAgAtBQJFEcJWJhhodHRwOi8vd3d3LnBvYm94LmNvbS9+dG16L3BncC90
bXouYXNjAAoJEEMlk4u+rwzjALoH/2i9Dd3c9Gu1oFa5hn4s2/xv/Ffim9i7oJyV
4VMmhUsCSeaqfHyM/4D4vZkgcmR6aOL3+WEObLQqfI18RHEvsLeoF/QPygURkmgg
0NdcqotsdM+zAX9dZ4jQMY/HiCzZyrlCuA9CN+qNlsKkLYIm2QRflKWqlms18hUA
bFvMWY73rxcSSFkwdZHnVaTS6uhftnaO7gXvA4+29FwpaKioJul1hFC5gmRv9wfU
hL/e17svWvFK1YCdySUl4JfxFG6Yy0DLWzNhK1lPEvVLwb3jO2D3g2MtTHVBQOsY
yi609ZBcjfGCuZSuNub9PZwzILvCW7UGVewowExyBvimBqXT0Kw=
=w6vo
-----END PGP SIGNATURE-----
More information about the fedora-list
mailing list