如何从命令行漂亮地打印具有长列的csv?
How to pretty print the csv which has long columns from command line?
我想从命令行查看和打印 this csv 文件。为此,我使用 csvlook nupic_out.csv | less -#2 -N -S
命令。问题是这个 csv 文件有很长的一列(它是第 5-multiStepPredictions.1)到这一列的所有内容都正确显示
1 -----------------+--------------------+-----------------------------+------------------------------------------------------------------------------------------------------------------------------------
2 angle | sine | multiStepPredictions.actual | multiStepPredictions.1
3 -----------------+--------------------+-----------------------------+------------------------------------------------------------------------------------------------------------------------------------
4 string | string | string | string
5 | | |
6 0.0 | 0.0 | 0.0 | None
7 0.0314159265359 | 0.0314107590781 | 0.0314107590781 | {0.0: 1.0}
8 0.0628318530718 | 0.0627905195293 | 0.0627905195293 | {0.0: 0.0039840637450199202 0.03141075907812829: 0.99601593625497931}
9 0.0942477796077 | 0.0941083133185 | 0.0941083133185 | {0.03141075907812829: 1.0}
10 0.125663706144 | 0.125333233564 | 0.125333233564 | {0.06279051952931337: 0.98942669172932329 0.03141075907812829: 0.010573308270676691}
11 0.157079632679 | 0.15643446504 | 0.15643446504 | {0.03141075907812829: 0.0040463956041429626 0.09410831331851431: 0.94917381047888194 0.06279051952931337: 0.04677979391
12 0.188495559215 | 0.187381314586 | 0.187381314586 | {0.12533323356430426: 0.85789473684210527 0.09410831331851431: 0.14210526315789476}
13 0.219911485751 | 0.218143241397 | 0.218143241397 | {0.15643446504023087: 0.63177315983686211 0.12533323356430426: 0.26859584385317475 0.09410831331851431: 0.09963099630
14 0.251327412287 | 0.248689887165 | 0.248689887165 | {0.06279051952931337: 0.3300438596491227 0.1873813145857246: 0.47381368550527647 0.15643446504023087: 0.12643231695
15 0.282743338823 | 0.278991106039 | 0.278991106039 | {0.21814324139654254: 0.56140350877192935 0.03141075907812829: 0.0032894736842105313 0.1873813145857246: 0.105263157894
16 0.314159265359 | 0.309016994375 | 0.309016994375 | {0.2486898871648548: 0.8228480378168288 0.03141075907812829: 0.0029688002160632981 0.1873813145857246: 0.022936632244020292
17 0.345575191895 | 0.338737920245 | 0.338737920245 | {0.2486898871648548: 0.13291723147401985 0.2789911060392293: 0.77025390613412514 0.21814324139654254: 0.06654338668
18 0.376991118431 | 0.368124552685 | 0.368124552685 | {0.2486898871648548: 0.10230061459892241 0.2789911060392293: 0.14992465949587844 0.21814324139654254: 0.06517018413
19 0.408407044967 | 0.397147890635 | 0.397147890635 | {0.33873792024529137: 0.67450197451277849 0.2486898871648548: 0.028274124758268366 0.2789911060392293: 0.077399230934
20 0.439822971503 | 0.425779291565 | 0.425779291565 | {0.33873792024529137: 0.17676914536466748 0.3681245526846779: 0.6509556160617509 0.2486898871648548: 0.04784688995215327
21 0.471238898038 | 0.45399049974 | 0.45399049974 | {0.33873792024529137: 0.038582651338955089 0.3681245526846779: 0.14813277049357607 0.2486898871648548: 0.029239766081
22 0.502654824574 | 0.481753674102 | 0.481753674102 | {0.3681245526846779: 0.035163881050575212 0.42577929156507266: 0.61447711863333254 0.2486898871648548: 0.015554881705
23 0.53407075111 | 0.50904141575 | 0.50904141575 | {0.33873792024529137: 0.076923076923077108 0.42577929156507266: 0.11307647489430354 0.45399049973954675: 0.66410206612
24 0.565486677646 | 0.535826794979 | 0.535826794979 | {0.42577929156507266: 0.035628438284964516 0.45399049973954675: 0.22906083786048709 0.3971478906347806: 0.014132015120
25 0.596902604182 | 0.562083377852 | 0.562083377852 | {0.5090414157503713: 0.51578106597362727 0.45399049973954675: 0.095000708551421106 0.06279051952931337: 0.08649420683
26 0.628318530718 | 0.587785252292 | 0.587785252292 | {0.5090414157503713: 0.10561370056909389 0.45399049973954675: 0.063130123291224485 0.5358267949789967: 0.617348556187
27 0.659734457254 | 0.612907053653 | 0.612907053653 | {0.5090414157503713: 0.036017118165629407 0.45399049973954675: 0.013316643552779454 0.5358267949789967: 0.236874795987
28 0.69115038379 | 0.637423989749 | 0.637423989749 | {0.2486898871648548: 0.037593984962406228 0.21814324139654254: 0.033834586466165564 0.5358267949789967: 0.085397996837
29 0.722566310326 | 0.661311865324 | 0.661311865324 | {0.6129070536529765: 0.49088597257034694 0.2486898871648548: 0.072573707671854309 0.06279051952931337: 0.04684445139
30 0.753982236862 | 0.684547105929 | 0.684547105929 | {0.6129070536529765: 0.16399317807418579 0.2486898871648548: 0.066194656736965368 0.2789911060392293: 0.015074193295
但是这个栏后面显示的都是垃圾
1 --------------------------------------------------------------------------------------------------------+--------------+---------------------------------+----------------------------+--------------+---
2 | anomalyScore | multiStepBestPredictions.actual | multiStepBestPredictions.1 | anomalyLabel | mu
3 --------------------------------------------------------------------------------------------------------+--------------+---------------------------------+----------------------------+--------------+---
4 | string | string | string | string | fl
5 | | | | |
6 | 1.0 | 0.0 | None | [] | 0
7 | 1.0 | 0.0314107590781 | 0.0 | [] | 10
8 | 1.0 | 0.0627905195293 | 0.0314107590781 | []
9 | 1.0 | 0.0941083133185 | 0.0314107590781 | [] | 66
10 | 1.0 | 0.125333233564 | 0.0627905195293 | []
11 | 1.0 | 0.15643446504 | 0.0941083133185 | []
12 | 1.0 | 0.187381314586 | 0.125333233564 | []
13 | 1.0 | 0.218143241397 | 0.15643446504 | []
14 | 1.0 | 0.248689887165 | 0.187381314586
15 | 1.0 | 0.278991106039 | 0.218143241397 |
16 | 1.0 | 0.309016994375 | 0.248689887165 | []
17 | 1.0 | 0.338737920245 | 0.278991106039
18 075907812829: 0.0008726186745285988 0.3090169943749474: 0.36571033632089267 0.15643446504023087: 0.15263157894736851} | 1.0 | 0.368124552685 | 0.30
19 69943749474: 0.12243639244611626 0.15643446504023087: 0.076923076923077024} | 1.0 | 0.397147890635 | 0.33873792
20 474: 0.042824288244468607} | 1.0 | 0.425779291565 | 0.368124552685
21 78906347806: 0.72014752277063943 0.3090169943749474: 0.019779736758565116} | 1.0 | 0.45399049974 | 0.39714789
22 323356430426: 0.030959752321981428 0.09410831331851431: 0.027863777089783253} | 1.0 | 0.481753674102 | 0.425779291
23 831331851431: 0.036437246963562819} | 1.0 | 0.50904141575 | 0.45399049974
24 831331851431: 0.011027980232581683} | 1.0 | 0.535826794979 | 0.481753674102
25 929156507266: 0.027856989831229011 0.15643446504023087: 0.02066616653788458 0.09410831331851431: 0.016739594895686508} | 1.0 | 0.562083377852 | 0.5090
26 13145857246: 0.08333333333333337 0.42577929156507266: 0.025020076940584089} | 1.0 | 0.587785252292 | 0.5358
27 075907812829: 0.0025974025974026035 0.5620833778521306: 0.59566175023106149} | 1.0 | 0.612907053653 | 0.5620833778
28 33778521306: 0.19639042255084313} one | 1.0 | 0.637423989749 | 0.587785252292
29 13145857246: 0.0046487548012272466 0.21814324139654254: 0.070071166027997234 0.5620833778521306: 0.087432430700408653} | 1.0 | 0.661311865324 | 0.612
30 39897486896: 0.53158336716673826 0.3090169943749474: 0.016749103661249369 0.5620833778521306: 0.027323827946545261} | 1.0 | 0.684547105929 | 0.6
如何漂亮地打印整个 csv?
PS:类似的垃圾也会产生以下命令(灵感here):
column -s, -t < nupic_out.csv | less -#2 -N -S
csvtool readable nupic_out.csv | less -#2 -N -S
我相信 csvlook
像对待任何其他字符一样对待该列中的制表符,并且不知道它们的特殊行为。
使列对齐的最简单方法是最小化选项卡:
expand -t1 nupic_out.csv | csvlook
我想从命令行查看和打印 this csv 文件。为此,我使用 csvlook nupic_out.csv | less -#2 -N -S
命令。问题是这个 csv 文件有很长的一列(它是第 5-multiStepPredictions.1)到这一列的所有内容都正确显示
1 -----------------+--------------------+-----------------------------+------------------------------------------------------------------------------------------------------------------------------------
2 angle | sine | multiStepPredictions.actual | multiStepPredictions.1
3 -----------------+--------------------+-----------------------------+------------------------------------------------------------------------------------------------------------------------------------
4 string | string | string | string
5 | | |
6 0.0 | 0.0 | 0.0 | None
7 0.0314159265359 | 0.0314107590781 | 0.0314107590781 | {0.0: 1.0}
8 0.0628318530718 | 0.0627905195293 | 0.0627905195293 | {0.0: 0.0039840637450199202 0.03141075907812829: 0.99601593625497931}
9 0.0942477796077 | 0.0941083133185 | 0.0941083133185 | {0.03141075907812829: 1.0}
10 0.125663706144 | 0.125333233564 | 0.125333233564 | {0.06279051952931337: 0.98942669172932329 0.03141075907812829: 0.010573308270676691}
11 0.157079632679 | 0.15643446504 | 0.15643446504 | {0.03141075907812829: 0.0040463956041429626 0.09410831331851431: 0.94917381047888194 0.06279051952931337: 0.04677979391
12 0.188495559215 | 0.187381314586 | 0.187381314586 | {0.12533323356430426: 0.85789473684210527 0.09410831331851431: 0.14210526315789476}
13 0.219911485751 | 0.218143241397 | 0.218143241397 | {0.15643446504023087: 0.63177315983686211 0.12533323356430426: 0.26859584385317475 0.09410831331851431: 0.09963099630
14 0.251327412287 | 0.248689887165 | 0.248689887165 | {0.06279051952931337: 0.3300438596491227 0.1873813145857246: 0.47381368550527647 0.15643446504023087: 0.12643231695
15 0.282743338823 | 0.278991106039 | 0.278991106039 | {0.21814324139654254: 0.56140350877192935 0.03141075907812829: 0.0032894736842105313 0.1873813145857246: 0.105263157894
16 0.314159265359 | 0.309016994375 | 0.309016994375 | {0.2486898871648548: 0.8228480378168288 0.03141075907812829: 0.0029688002160632981 0.1873813145857246: 0.022936632244020292
17 0.345575191895 | 0.338737920245 | 0.338737920245 | {0.2486898871648548: 0.13291723147401985 0.2789911060392293: 0.77025390613412514 0.21814324139654254: 0.06654338668
18 0.376991118431 | 0.368124552685 | 0.368124552685 | {0.2486898871648548: 0.10230061459892241 0.2789911060392293: 0.14992465949587844 0.21814324139654254: 0.06517018413
19 0.408407044967 | 0.397147890635 | 0.397147890635 | {0.33873792024529137: 0.67450197451277849 0.2486898871648548: 0.028274124758268366 0.2789911060392293: 0.077399230934
20 0.439822971503 | 0.425779291565 | 0.425779291565 | {0.33873792024529137: 0.17676914536466748 0.3681245526846779: 0.6509556160617509 0.2486898871648548: 0.04784688995215327
21 0.471238898038 | 0.45399049974 | 0.45399049974 | {0.33873792024529137: 0.038582651338955089 0.3681245526846779: 0.14813277049357607 0.2486898871648548: 0.029239766081
22 0.502654824574 | 0.481753674102 | 0.481753674102 | {0.3681245526846779: 0.035163881050575212 0.42577929156507266: 0.61447711863333254 0.2486898871648548: 0.015554881705
23 0.53407075111 | 0.50904141575 | 0.50904141575 | {0.33873792024529137: 0.076923076923077108 0.42577929156507266: 0.11307647489430354 0.45399049973954675: 0.66410206612
24 0.565486677646 | 0.535826794979 | 0.535826794979 | {0.42577929156507266: 0.035628438284964516 0.45399049973954675: 0.22906083786048709 0.3971478906347806: 0.014132015120
25 0.596902604182 | 0.562083377852 | 0.562083377852 | {0.5090414157503713: 0.51578106597362727 0.45399049973954675: 0.095000708551421106 0.06279051952931337: 0.08649420683
26 0.628318530718 | 0.587785252292 | 0.587785252292 | {0.5090414157503713: 0.10561370056909389 0.45399049973954675: 0.063130123291224485 0.5358267949789967: 0.617348556187
27 0.659734457254 | 0.612907053653 | 0.612907053653 | {0.5090414157503713: 0.036017118165629407 0.45399049973954675: 0.013316643552779454 0.5358267949789967: 0.236874795987
28 0.69115038379 | 0.637423989749 | 0.637423989749 | {0.2486898871648548: 0.037593984962406228 0.21814324139654254: 0.033834586466165564 0.5358267949789967: 0.085397996837
29 0.722566310326 | 0.661311865324 | 0.661311865324 | {0.6129070536529765: 0.49088597257034694 0.2486898871648548: 0.072573707671854309 0.06279051952931337: 0.04684445139
30 0.753982236862 | 0.684547105929 | 0.684547105929 | {0.6129070536529765: 0.16399317807418579 0.2486898871648548: 0.066194656736965368 0.2789911060392293: 0.015074193295
但是这个栏后面显示的都是垃圾
1 --------------------------------------------------------------------------------------------------------+--------------+---------------------------------+----------------------------+--------------+---
2 | anomalyScore | multiStepBestPredictions.actual | multiStepBestPredictions.1 | anomalyLabel | mu
3 --------------------------------------------------------------------------------------------------------+--------------+---------------------------------+----------------------------+--------------+---
4 | string | string | string | string | fl
5 | | | | |
6 | 1.0 | 0.0 | None | [] | 0
7 | 1.0 | 0.0314107590781 | 0.0 | [] | 10
8 | 1.0 | 0.0627905195293 | 0.0314107590781 | []
9 | 1.0 | 0.0941083133185 | 0.0314107590781 | [] | 66
10 | 1.0 | 0.125333233564 | 0.0627905195293 | []
11 | 1.0 | 0.15643446504 | 0.0941083133185 | []
12 | 1.0 | 0.187381314586 | 0.125333233564 | []
13 | 1.0 | 0.218143241397 | 0.15643446504 | []
14 | 1.0 | 0.248689887165 | 0.187381314586
15 | 1.0 | 0.278991106039 | 0.218143241397 |
16 | 1.0 | 0.309016994375 | 0.248689887165 | []
17 | 1.0 | 0.338737920245 | 0.278991106039
18 075907812829: 0.0008726186745285988 0.3090169943749474: 0.36571033632089267 0.15643446504023087: 0.15263157894736851} | 1.0 | 0.368124552685 | 0.30
19 69943749474: 0.12243639244611626 0.15643446504023087: 0.076923076923077024} | 1.0 | 0.397147890635 | 0.33873792
20 474: 0.042824288244468607} | 1.0 | 0.425779291565 | 0.368124552685
21 78906347806: 0.72014752277063943 0.3090169943749474: 0.019779736758565116} | 1.0 | 0.45399049974 | 0.39714789
22 323356430426: 0.030959752321981428 0.09410831331851431: 0.027863777089783253} | 1.0 | 0.481753674102 | 0.425779291
23 831331851431: 0.036437246963562819} | 1.0 | 0.50904141575 | 0.45399049974
24 831331851431: 0.011027980232581683} | 1.0 | 0.535826794979 | 0.481753674102
25 929156507266: 0.027856989831229011 0.15643446504023087: 0.02066616653788458 0.09410831331851431: 0.016739594895686508} | 1.0 | 0.562083377852 | 0.5090
26 13145857246: 0.08333333333333337 0.42577929156507266: 0.025020076940584089} | 1.0 | 0.587785252292 | 0.5358
27 075907812829: 0.0025974025974026035 0.5620833778521306: 0.59566175023106149} | 1.0 | 0.612907053653 | 0.5620833778
28 33778521306: 0.19639042255084313} one | 1.0 | 0.637423989749 | 0.587785252292
29 13145857246: 0.0046487548012272466 0.21814324139654254: 0.070071166027997234 0.5620833778521306: 0.087432430700408653} | 1.0 | 0.661311865324 | 0.612
30 39897486896: 0.53158336716673826 0.3090169943749474: 0.016749103661249369 0.5620833778521306: 0.027323827946545261} | 1.0 | 0.684547105929 | 0.6
如何漂亮地打印整个 csv?
PS:类似的垃圾也会产生以下命令(灵感here):
column -s, -t < nupic_out.csv | less -#2 -N -S
csvtool readable nupic_out.csv | less -#2 -N -S
我相信 csvlook
像对待任何其他字符一样对待该列中的制表符,并且不知道它们的特殊行为。
使列对齐的最简单方法是最小化选项卡:
expand -t1 nupic_out.csv | csvlook