Open1
シェル芸
xargs
標準入力を読み取り、コマンドの引数として渡す
標準入力に出力された単語をスペースや改行区切りでグループ化してくれる
$ cat 1.txt
a b c
d e
f g
h
# 特にグループ化の指定がない場合は ARG_MAX の長さになるまでまとめられる
$ cat 1.txt | xargs echo <ここに標準入力の中身がグループ化されて渡される>
a b c d e f g h
# 1 単語ずつ
$ cat 1.txt | xargs -n 1 echo
a
b
c
d
e
f
g
h
# 3 単語ずつ
$ cat 1.txt | xargs -n 3 echo
a b c
d e f
g h
$ ls *.png
10_green.png 17_green.png 23_green.png 2_red.png 36_grey.png 42_steelblue.png 49_yellow.png 55_tomato.png 6_green.png
ls *.png | sed -E 's/(.*)png/\1png \1jpg/' | xargs -n 2 convert
-n: 標準入力から [文字列数] を受け取るたびに、1回コマンドを実行する。
http://x68000.q-e-d.net/~68user/unix/pickup?xargs