From 6dedddc545e2f1930bdc2256784eb1551bd4231d Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sun, 1 Feb 2026 00:49:15 +0900 Subject: feat(nuldoc): rewrite nuldoc in Ruby --- .../index.html | 56 ++++++++++++---------- 1 file changed, 31 insertions(+), 25 deletions(-) (limited to 'services/nuldoc/public/blog/posts/2025-03-27/zip-function-like-command-paste-command/index.html') diff --git a/services/nuldoc/public/blog/posts/2025-03-27/zip-function-like-command-paste-command/index.html b/services/nuldoc/public/blog/posts/2025-03-27/zip-function-like-command-paste-command/index.html index 75e953c2..3560fe20 100644 --- a/services/nuldoc/public/blog/posts/2025-03-27/zip-function-like-command-paste-command/index.html +++ b/services/nuldoc/public/blog/posts/2025-03-27/zip-function-like-command-paste-command/index.html @@ -80,28 +80,31 @@ a.txt

-
a1
-a2
-a3
+
a1
+a2
+a3
+

b.txt

-
b1
-b2
-b3
+
b1
+b2
+b3
+

ab.txt

-
a1
-b1
-a2
-b2
-a3
-b3
+
a1
+b1
+a2
+b2
+a3
+b3
+

ちょうど Python や Haskell などにある zip 関数のような動きをさせたい。 @@ -113,8 +116,9 @@ 記事タイトルに書いたように、paste コマンドを使うと実現できる。

-
$ paste -d '\
-' a.txt b.txt > ab.txt
+
$ paste -d '\
+' a.txt b.txt > ab.txt
+

paste コマンドは複数のファイルを引数に取り、それらを1行ずつ消費しながら -d で指定した文字で区切って出力する。-d は区切り文字の指定で、デフォルトだとタブ区切りになる。 @@ -123,22 +127,24 @@ ファイル名には - を指定でき、その場合は標準入力から読み込んで出力する。このとき paste - - のように複数回 - を指定すると、指定した回数の行ごとに連結することができる。例えば ab.txt だとこうなる。

-
$ paste - - < ab.txt
-a1	b1
-a2	b2
-a3	b3
+
$ paste - - < ab.txt
+a1	b1
+a2	b2
+a3	b3
+

これは標準入力を使うとき特有の挙動で、単に同じファイル名を指定してもこうはならない。

-
$ paste ab.txt ab.txt
-a1	a1
-b1	b1
-a2	a2
-b2	b2
-a3	a3
-b3	b3
+
$ paste ab.txt ab.txt
+a1	a1
+b1	b1
+a2	a2
+b2	b2
+a3	a3
+b3	b3
+

ときどき便利。 -- cgit v1.3-1-g0d28