The world ends in ed

ed, 35 characters

s/[a-zA-Z]*\([a-zA-Z]\)\|./\1/g
p
Q

So, the world ends in ed. As I like to be too literal, I decided to write to write the solution with ed - and apparently it is actually a programming language. It's surprisingly short, even considering many shorter solutions already exist in this thread. It would be nicer if I could use something other than [a-zA-Z], but considering ed isn't a programming language, it's actually good enough.

First, I would like to say this only parses the last line in file. It would be possible to parse more, just type , at beginning of two first lines (this specified "everything" range, as opposed to standard last line range), but that would increase code size to 37 characters.

Now for explanations. The first line does exactly what Perl solution does (except without support for Unicode characters). I haven't copied the Perl solution, I just invented something similar by coincidence.

The second line prints last line, so you could see the output. The third line forces quit - I have to do it, otherwise ed would print ? to remind you that you haven't saved the file.

Now for how to execute it. Well, it's very simple. Just run ed with the file containing test case, while piping my program, like that.

ed -s testcase < program

-s is silent. This prevents ed from outputing ugly file size at beginning. After all, I use it as a script, not editor, so I don't need metadata. If I wouldn't do that, ed would show file size that I couldn't prevent otherwise.


Perl 5, 18 bytes

s/\pL*(\pL)|./$1/g

Requires a -p command line switch. The named property L matches only letter characters A-Za-z. There are several hundred such named properties, but when dealing with ASCII text, very few of them are interesting. Besides \pL, the only other one of any real note is \pP, which matches punctuation.

Try it online!


Perl 5, 17 bytes

A one byte improvement by Dom Hastings

print/\pL*(\pL)/g

Requires -n (and -l to support multiple inputs).

Try it online!


Sample usage

$ more in.dat
asdf jkl;__zxcv~< vbnm,.qwer| |uiop
pigs, eat dogs; eat Bob: eat pigs
looc si siht ,gnitirw esreveR
99_bottles_of_beer_on_the_wall

$ perl -p ends-in-ed.pl < in.dat
flvmrp
ststbts
citwR
sfrnel

Javascript, 49

alert(prompt().replace(/.(?=[a-z])|[^a-z]/gi,''))

It uses a regular expression to remove all characters that come before a letter, as well as all non-letter characters. Then we're left with the last letter of each word.

Thanks to tomsmeding for a nice improvement.