PRINT like THIS
GNU sed, 28
Score includes +2 for -rz
passed to GNU sed.
s/(\S+\s*)(\S*)/\U\1\L\2/g
Test output
$ for t in 'Nineteen Eighty-Four (1984)' \
> 'Programming Puzzles & Code Golf -
> Hooray for Code Golf Stack Exchange!' \
> ' 2be or not 2be, that is the ~~~QuEsTiOn~~~' \
> '++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.'; do
> echo "$t" | sed -zrf PRINTlikeTHIS.sed
> done
NINETEEN eighty-four (1984)
PROGRAMMING puzzles & code GOLF -
HOORAY for CODE golf STACK exchange!
2BE or NOT 2be, THAT is THE ~~~question~~~
++++++++[>++++[>++>+++>+++>+<<<<-]>+>+>->>+[<]<-]>>.>---.+++++++..+++.>>.<-.<.+++.------.--------.>>+.>++.
$
Vim script, 22 21 bytes
nm Q vEUWvEuWQ|norm Q
Explanation:
The first command maps Q
to:
vEU
make word uppercase
W
go to next word
vEu
make word lowercase
W
go to next word
Q
repeat recursive mapping
and |norm Q
executes the mapping
Usage of the program
This is how you get Vim to read from stdin:
$ vim - -c 'nm Q vEUWvEuWQ|norm Q'
Vim: Reading from stdin
This is the first line!
This is the second line!
This is the third and last line I type to check if this works!
^D
This will open up Vim displaying this:
THIS is THE first LINE.
this IS the SECOND line.
THIS is THE third AND last LINE i TYPE to CHECK if THIS works!
~
~
~
Perl, 26 bytes
25 bytes code + 1 byte command line
s/\S+/++$i%2?uc$&:lc$&/eg
Thanks to ThisSuitIsBlackNot for fixing a couple of bugs!
Usage:
perl -p entry.pl