Re: sed "Hello, world!" program?

Tim Chase <[email protected]>
Newsgroups gmane.editors.sed.user
Message-ID <[email protected]>
On 2014-02-18 13:09, [email protected] wrote:
> Most programming languages have a "Hello, world!" example. Some
> might debate if sed is a "real" programming language. But sed at
> least resembles a programming language in many ways. Anyway,
> assuming sed is a programming language, what might be sed "Hello,
> world!" program?

Well, you can pull of a UUOC¹ using sed as a noop

  echo 'Hello, World!' | sed '$q'

or you can transform input into your desired string:

  echo | sed 's/.*/Hello, world!/;q'

or you can transform every input line into your desired string

  echo | sed 's/.*/Hello, world!/'

> I think the criteria are:
>  Prints "Hello, world!".
>  Is one of the simplest programs in the language
>  Can be useful to demonstrate the language.

I think the 3rd one is the closest to meeting those criteria.

> Perhaps this is a silly post. Or maybe it might interest someone,
> or make us think more about how sed works. 

Since sed is more often used as a filter than as a stand-alone
language, it feels a little awkward to coerce it into acting like a
stand-alone language.  That said, it doesn't stop people from doing
crazy things with sed like Tetris², Conway's game of life³, or a
Sudoku solver⁴.

-tkc


¹ http://www.catb.org/jargon/html/U/UUOC.html
² http://uuner.doslash.org/forfun/
³ http://permalink.gmane.org/gmane.editors.sed.user/3770
⁴ http://www.edwardrosten.com/code/sed/sedoku.sed
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.