On 2013-04-02 16:29, Sam Watkins wrote:
> > e.g. A=/usr/bin B=/bin sed 's/$A/$B/' <in >out # won't work
>
> > I'm also not representative of the sed community, but to suggest that
> > this is what people primarily use it for is just ignorant.
>
> Ok perhaps I misjudged that, and I was a bit harsh on sed. Sure, sed is
> good at running ed scripts over streams and this is useful, but it is not
> good at doing basic text replacement with arbitrary strings. We might
> want a separate simple tool for that. But because the complex sed exists,
> that simple and basic 'substitute' tool has not been included in unix.
Whether true or not, that doesn't make sed "suck". It just indicates that it is
being misused
> What is the shortest shell command you can write,
> that replaces $A with $B in a text stream for any A and B?
With some caveats, this is POSIX:
$ cat > file << EOF
> The path is /foo/bar.
> EOF
$ from=/foo/bar; to=/baz/qux; file=$(cat file) ; printf '%s\n' "${file//$from/$to}"
The path is /baz/qux.
> If I'm building a machine, I might want to use bolts.
> Generic, good quality bolts. I'd rather not use bolts that can also
> function as screws, nails and batteries.
Bad analogy. Sed is not a bolt, a screw, a nail or a battery. It is the metal
that goes into them.
Chris
- application/pgp-signature attachment: stored
Received on Tue Apr 02 2013 - 08:10:57 CEST