はじめに
treeコマンド結果の罫線を消したいことがあります。
$ tree ./directory0
./directory0
├── directory1
│ ├── directory2
│ │ ├── directory3
│ │ └── file3
│ └── file2
└── file1
そんな時に使えるfilterを書きました。
以下のように罫線が消えてタブでインデントされます。
Excel等に貼り付けて資料化するのに便利です。
$ tree ./directory0 -J | ./filter.sh
./directory0/
directory1/
directory2/
directory3/
file3
file2
file1
以下リポジトリで公開しています。
https://github.com/loftkun/indent-filter-for-tree
for Linux, Mac
前提条件
- jq
- python3.x
Usage
git clone https://github.com/loftkun/indent-filter-for-tree.git
cd indent-filter-for-tree/linux
tree ../test/directory0 -J | ./filter.sh
treeコマンドとの比較(再掲)
罫線が邪魔だが、、、
$ tree ./directory0
./directory0
├── directory1
│ ├── directory2
│ │ ├── directory3
│ │ └── file3
│ └── file2
└── file1
これならすっきり資料化できます。
$ tree ./directory0 -J | ./filter.sh
./directory0/
directory1/
directory2/
directory3/
file3
file2
file1
$
for Windows
前提条件
- Windows Powershell
Usage
filterを作成。IndentFilterと命名(filter.ps1を参照)。
PS C:\test> filter IndentFilter {
% { $_ -replace "^(.*[+,\\\\]-.*)$","$&\" } |
% { $_ -replace "\| " ,"`t" } |
% { $_ -replace "\+---" ,"`t" } |
% { $_ -replace "\\---" ,"`t" } |
% { $_ -replace " " ,"`t" } |
% { If ( $_ -notmatch "`t+$" ){$_} }
}
IndentFilterを使う
tree /F /A TARGET_DIRECTORY | IndentFilter
treeコマンドとの比較
罫線が邪魔だが、、、
PS C:\test> tree .\directory0 /F /A
C:\TEST\DIRECTORY0
| file1
|
\---directory1
| file2
|
\---directory2
| file3
|
\---directory3
PS C:\test>
これならすっきり資料化できます。
PS C:\test> tree .\directory0 /F /A | IndentFilter
C:\TEST\DIRECTORY0
file1
directory1\
file2
directory2\
file3
directory3\
PS C:\test>