TSV to HTML table

TSVをHTMLのtableタグに変換する。

目次

  1. 使い方
  2. 入力
  3. 出力
    1. バージョン
    2. ヘルプ
      1. ルート
      2. group-header
      3. inner-header
      4. none-header
    3. HTML
      1. group-header
        1. 行列ヘッダ
          1. tsv2table
          2. tsv2table -r b
          3. tsv2table -r B
          4. tsv2table -c r
          5. tsv2table -c B
          6. tsv2table -r b -c r
          7. tsv2table -r b -c B
          8. tsv2table -r B -c r
          9. tsv2table -r B -c B
        2. 列ヘッダ
          1. tsv2table -H c
          2. tsv2table -H c -c r
          3. tsv2table -H c -c B
        3. 行ヘッダ
          1. tsv2table
          2. tsv2table -r b
          3. tsv2table -r B
      2. inner-header
        1. tsv2table i
        2. tsv2table i -H r
        3. tsv2table i -s 2
        4. tsv2table i -S 2
        5. tsv2table i -s 2 -S 3
        6. tsv2table i -H r -s 2
        7. tsv2table i -H r -S 2
        8. tsv2table i -H r -s 2 -S 3
      3. none-header
        1. tsv2table n
      4. 属性
        1. none-header
        2. inner-header
        3. group-header

使い方

tsv2table [g|i|n]
tsv2table g [-H a|r|c|m] [-r t|b|B] [-c l|r|B]
tsv2table i [-H c|r] [-s 1..] [-S 1..]
tsv2table n

 TSVまたはCSVを入力する。入力方法は第一引数またはstdin。

tsv2table a.tsv
tsv2table a.csv
cat a.tsv | tsv2table
cat a.csv | tsv2table
echo -e '\tA\tB\n1\ta\tb\n2\tc\td' | tsv2table
tsv2table <(echo -e '\tA\tB\n1\ta\tb\n2\tc\td')

 TSVまたはCSVの1行目にシバンを書いて実行できる。コマンドや引数ごとTSV,CSVに含めることができて便利。

export PATH="$PATH":"$(pwd)/CSharp.TsvToHtmlTable.20201028082641/bin"
chmod + x $(pwd)/CSharp.TsvToHtmlTable.20201028082641/docs/csv/col_3_shebang.csv
./CSharp.TsvToHtmlTable.20201028082641/docs/csv/col_3_shebang.csv

shebang

./csv/col_3_shebang.csv
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw
col_3_shebang.csv
#!/usr/bin/env -S tsv2table -H c
あ,A,a,A,B,C,D,E,F,G
,,b,H,I,J,K,L,M,N
,B,c,OP,,QX,R,STZa,,U
,,d,V,W,,Y,,,b
い,,,c,d,e,f,g,h,i
う,,e,j,k,l,m,n,o,p
,C,,q,r,s,t,u,v,w

通常なら実行コマンドは cat col_3.csv | table -H c である。しかしこれをCSVのシバンに書くことで実行時に省略できる。

入力

サブコマンド

概要
ggroup-header外側にヘッダがある表を作る。ヘッダは包含関係を表現できる。空白セルがあると結合する。
iinner-header内側にヘッダがある表を作る。
nnone-headerヘッダがない表を作る。

common

位置引数

位置名前初期値候補値
1file入力ファイルパス(stdinでも可)

たとえば以下のようなTSVを使う。

-d ,としてデリミタを変更すればCSVも使える。

オプション引数

初期値候補値
-d--delimiter"\t"","等任意文字列。未指定のときはファイルの内容から"\t"か","のどちらかだと推測する。
-T--table-attributetable要素に付与する属性。
-l--logging-levele
ffatal致命的エラーのログのみ表示する。
eerrorエラー以上のログを表示する。
wwarn警告以上のログを表示する。
iinfoInfo以上のログを表示する。
ddebugDebug以上のログを表示する。
ttraceTraceログのみ表示する。

group-header

初期値候補値
-H--headera
aautoヘッダを推測する。
1行目1列目が空でなければ列ヘッダなし。
1行目に空がなければ行ヘッダは1行のみ。
rrow行ヘッダがある。
ccolumn列ヘッダがある。
mmatrix行列ヘッダがある。
-r--rowt
ttop行ヘッダを上端に配置する。
bbottom行ヘッダを下端に配置する。
Bboth行ヘッダを上下両端に配置する。
-c--columnl
lleft列ヘッダを左端に配置する。
rright列ヘッダを右端に配置する。
Bboth列ヘッダを左右両端に配置する。
-R--row-header-attribute行ヘッダに指定するHTML属性。
-C--common-header-attribute列ヘッダに指定するHTML属性。
-M--matrix-header-attribute四隅の空ヘッダに指定するHTML属性。

inner-header

初期値候補値
-H--headerc
ccolumn列がヘッダになる。
rrow行がヘッダになる。
-s--start11以上の整数。
-S--stop11以上の整数。
-A--header-attribute全ヘッダに指定したHTML属性を付与する。

none-header

common 引数のみ。

出力

バージョン

tsv2table version
tsv2table --version
tsv2table 0.0.1.0

ヘルプ

ルート

tsv2table help
tsv2table --help
        
tsv2table 0.0.1.0
(C) 2020 ytyaru
CC0 : https://creativecommons.org/publicdomain/zero/1.0/deed.ja
USAGE:
  TSVをHTMLのtableタグに変換する。
  tsv2talbe [g|i|n]
  tsv2talbe g [-H a|r|c|m] [-r t|b|B] [-c l|r|B]
  tsv2talbe i [-H c|r] [-s N] [-S N]
  tsv2talbe n

  g          (Default Verb) ヘッダが外側にある。

  i          ヘッダが内側にある。

  n          ヘッダがない。

  help       Display more information on a specific command.

  version    Display version information.

group-header

tsv2table help g
tsv2table g --help
tsv2table 0.0.1.0
(C) 2020 ytyaru
CC0 : https://creativecommons.org/publicdomain/zero/1.0/deed.ja
USAGE:
  TSVをHTMLのtableタグに変換する。
  tsv2talbe [g|i|n]
  tsv2talbe g [-H a|r|c|m] [-r t|b|B] [-c l|r|B]
  tsv2talbe i [-H c|r] [-s N] [-S N]
  tsv2talbe n

  -H, --header                        (Default: a) ヘッダ。

  -r, --row                           (Default: t) 行ヘッダ位置。

  -c, --column                        (Default: l) 列ヘッダ位置。

  -R, ----row-header-attributes       行ヘッダ属性。

  -C, ----column-header-attributes    列ヘッダ属性。

  -d, --delimiter                     (Default: 	) 入力の区切文字。引数にファイルパスが指定されているときは拡張子で特定する。

  -T, --table-attributes              table要素の属性。

  -l, --logging-level                 (Default: e) ログ出力する。指定したレベル以上のもののみ出力する。

  --help                              Display this help screen.

  --version                           Display version information.

  file (pos. 1)                       入力ファイルパス。

inner-header

tsv2table help i
tsv2table i --help
tsv2table 0.0.1.0
(C) 2020 ytyaru
CC0 : https://creativecommons.org/publicdomain/zero/1.0/deed.ja
USAGE:
  TSVをHTMLのtableタグに変換する。
  tsv2talbe [g|i|n]
  tsv2talbe g [-H a|r|c|m] [-r t|b|B] [-c l|r|B]
  tsv2talbe i [-H c|r] [-s N] [-S N]
  tsv2talbe n

  -H, --header               (Default: c) 指定した軸がヘッダになる。

  -s, --start                (Default: 1) ヘッダ開始位置。

  -S, --step                 (Default: 1) ヘッダを指定数だけ飛ばす。

  -A, --header-attributes    全ヘッダに指定した属性を付与する

  -d, --delimiter            (Default: 	) 入力の区切文字。引数にファイルパスが指定されているときは拡張子で特定する。

  -T, --table-attributes     table要素の属性。

  -l, --logging-level        (Default: e) ログ出力する。指定したレベル以上のもののみ出力する。

  --help                     Display this help screen.

  --version                  Display version information.

  file (pos. 1)              入力ファイルパス。

none-header

tsv2table help n
tsv2table n --help
tsv2table 0.0.1.0
(C) 2020 ytyaru
CC0 : https://creativecommons.org/publicdomain/zero/1.0/deed.ja
USAGE:
  TSVをHTMLのtableタグに変換する。
  tsv2talbe [g|i|n]
  tsv2talbe g [-H a|r|c|m] [-r t|b|B] [-c l|r|B]
  tsv2talbe i [-H c|r] [-s N] [-S N]
  tsv2talbe n

  -d, --delimiter           (Default: 	) 入力の区切文字。引数にファイルパスが指定されているときは拡張子で特定する。

  -T, --table-attributes    table要素の属性。

  -l, --logging-level       (Default: e) ログ出力する。指定したレベル以上のもののみ出力する。

  --help                    Display this help screen.

  --version                 Display version information.

  file (pos. 1)             入力ファイルパス。

HTML

group-header

行列ヘッダ

tsv2table

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table
ABC
1abc
2def
3ghi

tsv2table -r b

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -r b
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw
abcdeC
AB
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -r b
1abc
2def
3ghi
ABC

tsv2table -r B

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -r B
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw
abcdeC
AB
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -r B
ABC
1abc
2def
3ghi
ABC

tsv2table -c r

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -c r
ABC
abcde
ABCDEFGaA
HIJKLMNb
OPQXRSTZaUcB
VWYbd
cdefghi
jklmnope
qrstuvwC
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -c r
ABC
abc1
def2
ghi3

tsv2table -c B

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -c B
ABC
abcde
AaABCDEFGaA
bHIJKLMNb
BcOPQXRSTZaUcB
dVWYbd
cdefghi
ejklmnope
CqrstuvwC
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -c B
ABC
1abc1
2def2
3ghi3

tsv2table -r b -c r

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -r b -c r
ABCDEFGaA
HIJKLMNb
OPQXRSTZaUcB
VWYbd
cdefghi
jklmnope
qrstuvwC
abcdeC
AB
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -r b -c r
abc1
def2
ghi3
ABC

tsv2table -r b -c B

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -r b -c B
AaABCDEFGaA
bHIJKLMNb
BcOPQXRSTZaUcB
dVWYbd
cdefghi
ejklmnope
CqrstuvwC
abcdeC
AB
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -r b -c B
1abc1
2def2
3ghi3
ABC

tsv2table -r B -c r

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -r B -c r
ABC
abcde
ABCDEFGaA
HIJKLMNb
OPQXRSTZaUcB
VWYbd
cdefghi
jklmnope
qrstuvwC
abcdeC
AB
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -r B -c r
ABC
abc1
def2
ghi3
ABC

tsv2table -r B -c B

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table -r B -c B
ABC
abcde
AaABCDEFGaA
bHIJKLMNb
BcOPQXRSTZaUcB
dVWYbd
cdefghi
ejklmnope
CqrstuvwC
abcdeC
AB
cat ./res/tsv/matrix_1.tsv | ./bin/tsv2table -r B -c B
ABC
1abc1
2def2
3ghi3
ABC

列ヘッダ

tsv2table -H c

cat ./res/tsv/col_3.tsv | ./bin/tsv2table -H c
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw
cat ./res/tsv/col_1.tsv | ./bin/tsv2table -H c
Aabcd
Befgh
Cijkl
Dmnop

tsv2table -H c -c r

cat ./res/tsv/col_3.tsv | ./bin/tsv2table -H c -c r
ABCDEFGaA
HIJKLMNb
OPQXRSTZaUcB
VWYbd
cdefghi
jklmnope
qrstuvwC
cat ./res/tsv/col_1.tsv | ./bin/tsv2table -H c -c r
abcdA
efghB
ijklC
mnopD

tsv2table -H c -c B

cat ./res/tsv/col_3.tsv | ./bin/tsv2table -H c -c B
AaABCDEFGaA
bHIJKLMNb
BcOPQXRSTZaUcB
dVWYbd
cdefghi
ejklmnope
CqrstuvwC
cat ./res/tsv/col_1.tsv | ./bin/tsv2table -H c -c B
AabcdA
BefghB
CijklC
DmnopD

行ヘッダ

tsv2table

cat ./res/tsv/row_3.tsv | ./bin/tsv2table
ABC
abcde
ABCDEFG
HIJKLMN
OPQXRSTU
cat ./res/tsv/row_1.tsv | ./bin/tsv2table
ABCD
abcd
efgh
ijkl

tsv2table -c r

cat ./res/tsv/row_3.tsv | ./bin/tsv2table -r b
ABCDEFG
HIJKLMN
OPQXRSTU
abcdeC
AB
cat ./res/tsv/row_1.tsv | ./bin/tsv2table -r b
abcd
efgh
ijkl
ABCD

tsv2table -c B

cat ./res/tsv/row_3.tsv | ./bin/tsv2table -r B
ABC
abcde
ABCDEFG
HIJKLMN
OPQXRSTU
abcdeC
AB
cat ./res/tsv/row_1.tsv | ./bin/tsv2table -r B
ABCD
abcd
efgh
ijkl
ABCD

inner-header i

tsv2table

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table i -H r

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -H r
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table i -s 2

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -s 2
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table i -S 2

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -S 2
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table i -s 2 -S 3

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -s 2 -S 3
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table i -H r -s 2

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -H r -s 2
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table -H r -S 2

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -H r -S 2
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

tsv2table i -H r -s 2 -S 3

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table i -H r -s 2 -S 3
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

none-header n

cat ./res/tsv/matrix_3.tsv | ./bin/tsv2table n
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

属性

任意のHTML属性を指定箇所に与える。

none-header

cat ./tsv/matrix_3.tsv | ./bin/tsv2table n -T 'class="tsv2table"'
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

inner-header

cat ./tsv/matrix_3.tsv | ./bin/tsv2table i -T 'class="tsv2table"' -A 'class="i-header"'
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw

group-header

cat ./tsv/matrix_3.tsv | ./bin/tsv2table g -T 'class="tsv2table"' -R 'class="g-r-header"' -C 'class="g-c-header"'
ABC
abcde
AaABCDEFG
bHIJKLMN
BcOPQXRSTZaU
dVWYb
cdefghi
ejklmnop
Cqrstuvw
cat ./tsv/matrix_3.tsv | ./bin/tsv2table g -r B -c B -T 'class="tsv2table"' -R 'class="g-r-header"' -C 'class="g-c-header"'
ABC
abcde
AaABCDEFGaA
bHIJKLMNb
BcOPQXRSTZaUcB
dVWYbd
cdefghi
ejklmnope
CqrstuvwC
abcdeC
AB