Re: [dev] print utility

From: Chris Down <chris_AT_chrisdown.name>
Date: Tue, 2 Apr 2013 14:10:57 +0800

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

Received on Tue Apr 02 2013 - 08:10:57 CEST

This archive was generated by hypermail 2.3.0 : Tue Apr 02 2013 - 08:12:05 CEST