From 4681e861efcdf9b0b73e3803e70712bc55162863 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 8 Aug 2026 10:38:18 +0900 Subject: feat(slides): improve slide controller --- .../index.html | 58 ++++++++++++---------- 1 file changed, 32 insertions(+), 26 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 8a95b643..7968b9ec 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 @@ -15,7 +15,7 @@ zip 関数のようなコマンド paste|REPL: Rest-Eat-Program Loop - +
@@ -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