News for hackers. Stuff that matters.
Re:Copying stdin to stdout in Java by patio11 on Wednesday March 26, 2014 @04:07AM (#7472156)
Awk is even shorter: anything truthy works. You don't even need the print statement or brackets. Thus there are nine separate 1-byte programs which produce cat: [1], [2], [3], etc etc.

By default, unless you use the BEGIN block or something, awk will run your program on each line of stdlin. This is useful for programs of the type:

(/some regular expression/) { some action}

The default action if you don't specify one is "print $0" (the whole matching line). If your condition is a plain-ol' expression rather than a regular expression, and it always evaluates truthy, you thus get every line.

Re:Copying stdin to stdout in Java by acqq on Wednesday March 26, 2014 @04:30AM (#7472205)
You are right, the shortest awk is one byte. Please post the link all nine variants I wasn't able to Google it.

Still the shortest Perl is 0 bytes when the command line switch is allowed to be -p

Update: That's actually called "the sed mode of Perl." Moreover these two command lines behave similarly:

    perl -pe 's/search/replace/g'
and

    sed 's/search/replace/'
Re:Copying stdin to stdout in Java by dvdkhlng on Wednesday March 26, 2014 @04:48AM (#7472250)
SED is shorter (0 byte). SED /is/ a turing complete language [1] so don't try to claim that I'm cheating.

  sed < input > output 
:)

[1] http://robertkotcher.com/sed.html

[update] s/set/sed/

Re:Copying stdin to stdout in Java by acqq on Wednesday March 26, 2014 @05:08AM (#7472302)
The command line equivalent, with Perl:

    perl -pe '' <input >output
Re:Copying stdin to stdout in Java by Alphasite_ on Wednesday March 26, 2014 @06:07AM (#7472471)
Even java can do that setOut(system.in); (iirc)
Re:Copying stdin to stdout in Java by dvdkhlng on Wednesday March 26, 2014 @06:29AM (#7472532)
> Even java can do that setOut(system.in);

I was referring to an empty SED-program that would then be run via 'sed -f empty-file.sed'. Of course you need >0 bytes to invoke the SED program.