From 9d5ec5e3bc01c6174dea048e118edee579c36565 Mon Sep 17 00:00:00 2001 From: nsfisis Date: Sat, 7 Feb 2026 23:06:23 +0900 Subject: fix(style): fix codeblock style for rouge --- .../index.html | 58 ++++++++++------------ 1 file changed, 26 insertions(+), 32 deletions(-) (limited to 'services/nuldoc/public/blog/posts/2025-03-27/zip-function-like-command-paste-command') 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 052365e5..14e09c96 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,31 +80,28 @@ 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 関数のような動きをさせたい。 @@ -116,9 +113,8 @@ b3 記事タイトルに書いたように、paste コマンドを使うと実現できる。

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

paste コマンドは複数のファイルを引数に取り、それらを1行ずつ消費しながら -d で指定した文字で区切って出力する。-d は区切り文字の指定で、デフォルトだとタブ区切りになる。 @@ -127,24 +123,22 @@ b3 ファイル名には - を指定でき、その場合は標準入力から読み込んで出力する。このとき 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