是否有一个命令行工具,它采用分隔符分隔值的行并将它们排列在SQL样式的表中?如,
id,name
1,apple
2,banana
3,yogurt
到
id | name
----+---------
1 | apple
2 | banana
3 | yogurt
答案 0 :(得分:1)
输入文件:
$ cat file.scv
id,name
1,apple
2,banana
3,yogurt
<强>代码强>:
$ cat ./format-STDIN.pl
#!/usr/bin/env perl
use strict; use warnings;
sep();
while (<>) {
$. == 2 and sep();
format STDOUT =
|@<< | @<<<<<<<<<<<|
split /,/
.
write;
}
sep();
sub sep{ print "+----+-------------+\n"; }
<强>输出强>:
$ ./format-STDIN.pl file.csv
+----+-------------+
|id | name |
+----+-------------+
|1 | apple |
|2 | banana |
|3 | yogurt |
+----+-------------+