Re: sed "Hello, world!" program?

Tim Chase <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
On 2014-02-23 17:52, [email protected] wrote:
> So here is an alternate suggestion for the sed "Hello, world!"
> example for group members to consider:
> 
> ------------------------------
> # convert input text stream to "Hello, world!"
> s/.*/Hello, world!/
> q
> ------------------------------
> 
> sed is really two things in one: 1) the command-line utility. 2)
> the simple scripting language that the sed utility reads. By
> separating out the script from the command line environment, this
> example is immune (I think) to command line oddities like the C
> shell behavior and differences in sed versions.
> 
> So is this the best "Hello, world!" example? Or is there some other
> defect lurking, or some better way?

I think this is my favorite so far. It should be cross-platform with
the following benefits:

- no trouble escaping the "!"

- no trouble with single-vs-double quotes

- no need for a specific external utility (though "echo" still has
  fairly broad support) as long as you have *something* that produces
  output on stdout, including any arbitrary text file

- no dependency on redirecting-stderr notation

- demonstrates that sed scripts can be external files, not just the
  command command-line usage

- demonstrates use of the archetypal s/// command

So I'm +1 on this.

-tkc
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.