folding arguments
Root Boy Jim
rbj at icst-cmr.arpa
Wed Feb 17 10:47:47 AEST 1988
From: Rahul Dhesi <dhesi at bsu-cs.uucp>
Date: 12 Feb 88 15:14:46 GMT
In article <120 at gsg.UUCP> lew at gsg.UUCP (Paul Lew) writes:
> $ find $DIR -print | awk '{print "command",$0}' | sh (flexible)
>or:
> $ find $DIR -print | sed 's/^/command /' | sh (fast)
The original author mentioned that xargs (the obvious and best)
solution is a System V solution. So get those tapes out and port it,
as well as cpio and maybe a few others. You are already licensed for
it if you are running BSD. In any case, a PD version has been posted
to the source groups.
Me, I prefer:
$ find $DIR -exec command {} \;
However, the original poster wanted to give the command as many
arguments as possible, so it would be invoked less often, presumably
because efficiency was important to him. Something like the original
fa, which folds argument lists into manageable size, is essential
in that case. In a pinch I would try something like this:
$ find $DIR -print | nroff | sed -e 's/ */ /g' | ...
Since nroff right-justifies by default, we use sed to squeeze multiple
blanks to a single blank so "while read" in sh will work. (Not
tested.)
Now we're getting somewhere. Indeed, such an `fa' type program exists;
it is called `fmt'. So one might try:
% find $DIR -print | fmt | sed 's/^/cmd /' | sh
It is a pity that fmt is hardwired with a line size of 72 columns. Fold,
which does believe in differing line sizes, chops things up without
regard for word boundarys. These two programs could easily be merged.
Rahul Dhesi UUCP: <backbones>!{iuvax,pur-ee,uunet}!bsu-cs!dhesi
(Root Boy) Jim Cottrell <rbj at icst-cmr.arpa>
National Bureau of Standards
Flamer's Hotline: (301) 975-5688
OKAY!! Turn on the sound ONLY for TRYNEL CARPETING,
FULLY-EQUIPPED R.V.'S and FLOATATION SYSTEMS!!
More information about the Comp.unix.wizards
mailing list