2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sublime text > csvの表示書式をmarkdown用に変更する > 閲覧にも使える

Last updated at Posted at 2015-08-29

以下のようなcsvファイルがあるとする。

yy/mm/dd,hh:nn:ss,errorLevel,summary,detail,functionAndIndex
15/08/29,11:04:39,0(High),UDP:Summary1,Detail1,funcA:idx1
15/08/29,11:04:39,1(Middle),UDP:Summary2,Detail2,funcA:idx2
15/08/29,11:04:39,0(High),PC:Summary1,Detail3,funcB:idx1
15/08/29,11:04:39,2(Low),PC:Summary2,Detail4,funcAdd:idx2
15/08/29,11:04:39,0(High),PC:Summary3,Detail5,funcRemove:idx3
15/08/29,11:04:39,3(Debug),Debug:Hello world,Detail5,
15/08/29,11:04:39,4(Info),Not problem but,This is not a problem,
15/08/29,11:04:39,0(High),UDP:Summary1,Detail1,funcA:idx1
15/08/29,11:04:39,1(Middle),UDP:Summary2,Detail2,funcA:idx2
15/08/29,11:04:39,0(High),PC:Summary1,Detail3,funcB:idx1
15/08/29,11:04:39,2(Low),PC:Summary2,Detail4,funcAdd:idx2
15/08/29,11:04:39,0(High),PC:Summary3,Detail5,funcRemove:idx3
15/08/29,11:04:39,3(Debug),Debug:Hello world,Detail5,
15/08/29,11:04:39,4(Info),Not problem but,This is not a problem,
15/08/29,11:04:39,0(High),UDP:Summary1,Detail1,funcA:idx1
15/08/29,11:04:39,1(Middle),UDP:Summary2,Detail2,funcA:idx2
15/08/29,11:04:39,0(High),PC:Summary1,Detail3,funcB:idx1
15/08/29,11:04:39,2(Low),PC:Summary2,Detail4,funcAdd:idx2
15/08/29,11:04:39,0(High),PC:Summary3,Detail5,funcRemove:idx3
15/08/29,11:04:39,3(Debug),Debug:Hello world,Detail5,
15/08/29,11:04:39,4(Info),Not problem but,This is not a problem,

見にくい。テーブルのようにして列がそろった状態で見たい。
でもEXCEL(が入っている別のvmイメージを)立ち上げるのはめんどくさい。
linuxに渡してbashで処理するのもめんどくさい。

Sublime Textで何かありそうと思ったら、以下のリンクを見つけた。

##前準備
Package Control > Install > Table Editor(SublimeTAbleEditor)をインストール

##使用

  1. 変換したいcsvファイル(拡張子はtxtなどでもOK)をSublime Textで開く
  2. 領域を選択する
  3. Ctrl+k
  4. Shift+\ ("|"のキー)

上記でうまくいかなかったら、Ctrl+Shift+P > "Table Editor: Enable for current syntax"

Ctrl+Shift+P > "Table Editor: Enable for current view"
などする必要があるかも。

なお、view -> Plain TextのままでもOKだった。

##結果

| yy/mm/dd | hh:nn:ss | errorLevel | summary           | detail                | functionAndIndex |
| 15/08/29 | 11:04:39 | 0(High)    | UDP:Summary1      | Detail1               | funcA:idx1       |
| 15/08/29 | 11:04:39 | 1(Middle)  | UDP:Summary2      | Detail2               | funcA:idx2       |
| 15/08/29 | 11:04:39 | 0(High)    | PC:Summary1       | Detail3               | funcB:idx1       |
| 15/08/29 | 11:04:39 | 2(Low)     | PC:Summary2       | Detail4               | funcAdd:idx2     |
| 15/08/29 | 11:04:39 | 0(High)    | PC:Summary3       | Detail5               | funcRemove:idx3  |
| 15/08/29 | 11:04:39 | 3(Debug)   | Debug:Hello world | Detail5               |                  |
| 15/08/29 | 11:04:39 | 4(Info)    | Not problem but   | This is not a problem |                  |
| 15/08/29 | 11:04:39 | 0(High)    | UDP:Summary1      | Detail1               | funcA:idx1       |
| 15/08/29 | 11:04:39 | 1(Middle)  | UDP:Summary2      | Detail2               | funcA:idx2       |
| 15/08/29 | 11:04:39 | 0(High)    | PC:Summary1       | Detail3               | funcB:idx1       |
| 15/08/29 | 11:04:39 | 2(Low)     | PC:Summary2       | Detail4               | funcAdd:idx2     |
| 15/08/29 | 11:04:39 | 0(High)    | PC:Summary3       | Detail5               | funcRemove:idx3  |
| 15/08/29 | 11:04:39 | 3(Debug)   | Debug:Hello world | Detail5               |                  |
| 15/08/29 | 11:04:39 | 4(Info)    | Not problem but   | This is not a problem |                  |
| 15/08/29 | 11:04:39 | 0(High)    | UDP:Summary1      | Detail1               | funcA:idx1       |
| 15/08/29 | 11:04:39 | 1(Middle)  | UDP:Summary2      | Detail2               | funcA:idx2       |
| 15/08/29 | 11:04:39 | 0(High)    | PC:Summary1       | Detail3               | funcB:idx1       |
| 15/08/29 | 11:04:39 | 2(Low)     | PC:Summary2       | Detail4               | funcAdd:idx2     |
| 15/08/29 | 11:04:39 | 0(High)    | PC:Summary3       | Detail5               | funcRemove:idx3  |
| 15/08/29 | 11:04:39 | 3(Debug)   | Debug:Hello world | Detail5               |                  |
| 15/08/29 | 11:04:39 | 4(Info)    | Not problem but   | This is not a problem |                  |

変換に失敗する時

(追記 2016/07/12)

うまく変換できない場合は「すべての行が同じ列数であるか」を確認する。
1つでも列数が多いものが入ると変換に失敗するようだ。

日本語が含まれる場合

変換したい文字列に日本語(Shift_JIS)が含まれる場合、"|"の位置が行ごとにばらばらになってしまうようだ。

2
4
1

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?