LoginSignup
9
4

More than 5 years have passed since last update.

各言語処理系でワンライナーを走らせる方法カンペ

Posted at

awk

$ echo -e '10\n20' | awk '{print $1 * 2}'
20
40

Perl

$ perl -le 'print uc"hoge"'
HOGE
$ echo -e '10\n20' | perl -nle 'print $_ * 2'
20
40

PHP

$ php -r 'echo strtoupper("hoge");'
HOGE
$ echo -e '10\n20' | php -R 'echo $argn * 2 . PHP_EOL;'
20
40

Node.js

$ node -e 'console.log("hoge".toUpperCase())'
HOGE
$ node -p '"hoge".toUpperCase()'
HOGE
$ echo -e '10\n20' | node -e 'process.stdin.on("data", buf => console.log(buf.toString().trim().split("\n").map(n => n * 2).join("\n")))'
20
40

Ruby

$ ruby -e 'puts "hoge".upcase'
HOGE
$ echo -e '10\n20' | ruby -ne 'puts $_.to_i * 2'
20
40

Python

$ python -c 'print "hoge".upper()'
HOGE
$ echo -e '10\n20' | python -c 'import sys; print "\n".join(str(int(n) * 2) for n in sys.stdin)'
20
40

CoffeeScript

$ coffee -e 'console.log "hoge".toUpperCase()'
HOGE

LiveScript

$ lsc -de '"hoge".to-upper-case! |> console.log'
HOGE
9
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
4