| Newsgroups |
gmane.editors.sed.user |
| Message-ID |
<[email protected]> |
Thanks for the reply. I don't see a huge burst of interest from other group members. :)
Anyway, taking into account your suggestions, and after a little thought, I would like to suggest the following as candidate for "official" :) sed "Hello, World!":
sed --version | sed 's/.*/Hello, world!/; q'
This "Hello, world!" has the following advantages:
1) Like sed, it is unique. No other language has a "Hello, World!" even vaguely similar.
2) Like sed, it is relatively simple and short, one line.
3) It points out a unique attribute of the sed "language", that it MUST have input.
4) It does not rely on "echo" or other non-sed command (that may not be present). It makes it's own input, whatever text --version happens to produce. Maybe some sed versions may not have --version option? But it is a standard command line option, so I think it is fine for this purpose.
5) It does a good job demonstrating sed: It uses the key s command. And it shows how to write a simple program to quit after processing the first line.
6) It shows the script needs to be quoted if there is an included blank.
I take it some sed versions do not support semicolon. So I would suggest also having an alternate form:
sed --version | sed -e 's/.*/Hello, world!/' -e 'q'
Advantages of the alternate "Hello, world!" are that it shows how multiple scripts can be combined into one script, and it shows the use of a sed command line option that might be used in real operation.
Anyway, if I don't hear back after a week or so, I will try adding to wikipedia.
Daniel