将ls输出转换为csv [英] Convert ls output into csv
本文介绍了将ls输出转换为csv的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我将如何转换:
$ find . -ls > /tmp/files.txt
哪个给了我类似的东西
908715 40 -rwxrwxr-x 1 david staff 16542 Nov 15 14:12 ./dump_info.py
908723 0 drwxr-xr-x 2 david staff 68 Nov 20 17:35 ./metadata
转换为csv输出?看起来像:
Into a csv output? It would look like:
908715,40,-rwxrwxr-x,1,david,staff,16542,Nov 15 14:12,./dump_info.py
908723,0,drwxr-xr-x,2,david,staff,68,Nov 20 17:35,./metadata
下面是示例标题,文件名中带有空格:
Here is an example title with spaces in the filename:
652640,80,-rw-rw-r--,1,david,staff,40036,Nov,6,15:32,./v_all_titles/V Catalog Report 11.5.xlsx
推荐答案
在命令行中键入会有点长,但它会在文件名中正确保留空格(并用引号引起来!)
It's a bit long to type in at the command-line, but it properly preserves spaces in the filename (and quotes it, too!)
find . -ls | python -c '
import sys
for line in sys.stdin:
r = line.strip("\n").split(None, 10)
fn = r.pop()
print ",".join(r) + ",\"" + fn.replace("\"", "\"\"") + "\""
'
这篇关于将ls输出转换为csv的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文