先日行われた第26回シェル芸勉強会の復習中、よさげなツールがないか調べてたところXMLやCSVを平文フォーマットで「位置情報=値」といった形式に変換できるというxml2・csv2というツールを見かけた。 インストールは以下のコマンドで行える。
yum install xml2 # RHEL系の場合
apt install xml2 # UbuntuなどDebian系の場合
インストール後、以下のように標準出力から受けとることでXMLやCSVを整形してくれる。
コマンド | xml2 # XMLの場合
コマンド | csv2 # CSVの場合
XMLの場合
blacknon@BS-PUB-UBUNTU-01:~/ShellGeiData/vol.26_work$ unzip -p hanshin.xlsx xl/sharedStrings.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<sst xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" count="18" uniqueCount="15"><si><t>真弓</t><rPh sb="0" eb="2"><t>マユミ</t></rPh><phoneticPr fontId="1" /></si><si><t>弘田</t><rPh sb="0" eb="2"><t>ヒロタ</t></rPh><phoneticPr fontId="1" /></si><si><t>バース</t><phoneticPr fontId="1" /></si><si><t>掛布</t><rPh sb="0" eb="2"><t>カケフ</t></rPh><phoneticPr fontId="1" /></si><si><t>岡田</t><rPh sb="0" eb="2"><t>オカd</t></rPh><phoneticPr fontId="1" /></si><si><t>佐野</t><rPh sb="0" eb="2"><t>サノ</t></rPh><phoneticPr fontId="1" /></si><si><t>平田</t><rPh sb="0" eb="2"><t>ヒラt</t></rPh><phoneticPr fontId="1" /></si><si><t>木戸</t><rPh sb="0" eb="2"><t>キド</t></rPh><phoneticPr fontId="1" /></si><si><t>ゲイル</t><phoneticPr fontId="1" /></si><si><t>北村</t><rPh sb="0" eb="2"><t>キタムr</t></rPh><phoneticPr fontId="1" /></si><si><t>掛布</t><rPh sb="0" eb="2"><t>カケf</t></rPh><phoneticPr fontId="1" /></si><si><t>佐野</t><rPh sb="0" eb="2"><t>サn</t></rPh><phoneticPr fontId="1" /></si><si><t>木戸</t><rPh sb="0" eb="2"><t>キd</t></rPh><phoneticPr fontId="1" /></si><si><t>永尾</t><rPh sb="0" eb="2"><t>ナガ</t></rPh><phoneticPr fontId="1" /></si><si><t>池 田</t><rPh sb="0" eb="2"><t>イケd</t></rPh><phoneticPr fontId="1" /></si></sst>blacknon@BS-PUB-UBUNTU-01:~/ShellGeiData/vol.26_work$
blacknon@BS-PUB-UBUNTU-01:~/ShellGeiData/vol.26_work$ unzip -p hanshin.xlsx xl/sharedStrings.xml | xml2
/sst/@xmlns=http://schemas.openxmlformats.org/spreadsheetml/2006/main
/sst/@count=18
/sst/@uniqueCount=15
/sst/si/t=真弓
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=マユミ
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=弘田
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=ヒロタ
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=バース
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=掛布
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=カケフ
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=岡田
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=オカd
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=佐野
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=サノ
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=平田
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=ヒラt
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=木戸
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=キド
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=ゲイル
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=北村
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=キタムr
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=掛布
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=カケf
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=佐野
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=サn
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=木戸
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=キd
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=永尾
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=ナガ
/sst/si/phoneticPr/@fontId=1
/sst/si
/sst/si/t=池田
/sst/si/rPh/@sb=0
/sst/si/rPh/@eb=2
/sst/si/rPh/t=イケd
/sst/si/phoneticPr/@fontId=1
CSVの場合
blacknon@BS-PUB-UBUNTU-01:~/ShellGeiData/vol.26_work$ xlsx2csv graph.xlsx
0,-5
0.5,-7.375
1,-14
1.5,-24.125
2,-37
2.5,-51.875
3,-68
3.5,-84.625
4,-101
4.5,-116.375
5,-130
5.5,-141.125
6,-149
6.5,-152.875
7,-152
7.5,-145.625
8,-133
8.5,-113.375
9,-86
9.5,-50.125
10,-5
10.5,50.125
11,116
blacknon@BS-PUB-UBUNTU-01:~/ShellGeiData/vol.26_work$ xlsx2csv graph.xlsx | csv2
/file/record
/file/record/@num=0
/file/record/field0=0
/file/record/field1=-5
/file/record
/file/record/@num=1
/file/record/field0=0.5
/file/record/field1=-7.375
/file/record
/file/record/@num=2
/file/record/field0=1
/file/record/field1=-14
/file/record
/file/record/@num=3
/file/record/field0=1.5
/file/record/field1=-24.125
/file/record
/file/record/@num=4
/file/record/field0=2
/file/record/field1=-37
/file/record
/file/record/@num=5
/file/record/field0=2.5
/file/record/field1=-51.875
/file/record
/file/record/@num=6
/file/record/field0=3
/file/record/field1=-68
/file/record
/file/record/@num=7
/file/record/field0=3.5
/file/record/field1=-84.625
/file/record
/file/record/@num=8
/file/record/field0=4
/file/record/field1=-101
/file/record
/file/record/@num=9
/file/record/field0=4.5
/file/record/field1=-116.375
/file/record
/file/record/@num=10
/file/record/field0=5
/file/record/field1=-130
/file/record
/file/record/@num=11
/file/record/field0=5.5
/file/record/field1=-141.125
/file/record
/file/record/@num=12
/file/record/field0=6
/file/record/field1=-149
/file/record
/file/record/@num=13
/file/record/field0=6.5
/file/record/field1=-152.875
/file/record
/file/record/@num=14
/file/record/field0=7
/file/record/field1=-152
/file/record
/file/record/@num=15
/file/record/field0=7.5
/file/record/field1=-145.625
/file/record
/file/record/@num=16
/file/record/field0=8
/file/record/field1=-133
/file/record
/file/record/@num=17
/file/record/field0=8.5
/file/record/field1=-113.375
/file/record
/file/record/@num=18
/file/record/field0=9
/file/record/field1=-86
/file/record
/file/record/@num=19
/file/record/field0=9.5
/file/record/field1=-50.125
/file/record
/file/record/@num=20
/file/record/field0=10
/file/record/field1=-5
/file/record
/file/record/@num=21
/file/record/field0=10.5
/file/record/field1=50.125
/file/record
/file/record/@num=22
/file/record/field0=11
/file/record/field1=116
なお、これらの逆についても変換できるようなので、一度変換した後に編集して再度元に戻したりといった使い方もできるようだ。