我需要通过mac控制台窗口获取文件夹的内容 并通过> output.txt:
放入文本文件现有结构如下:
folder/index.html
folder/images/backpack.png
folder/shared/bootstrap/fonts/helvertica.eot
folder/css/fonts/helverticabold.eot
folder/shared/css/astyle.css
folder/js/libs/jquery-ui-1.10.4/jquery-ui.min.js",
folder/js/libs/jquery.tipsy.js
folder/js/libs/raphael.js
我想要的外观看起来像这样(文件夹丢失):
index.html
images/backpack.png
shared/bootstrap/fonts/helvertica.eot
css/fonts/helverticabold.eot
shared/css/astyle.css
js/libs/jquery-ui-1.10.4/jquery-ui.min.js
js/libs/jquery.tipsy.js
js/libs/raphael.js
未列出css / fonts或js / libs或css文件夹 即没有文件夹... ..而且没有像
这样的格式/folder/shared/css/astyle.css或 ./folder/shared/css/astyle.css
用parens和逗号来表示更好:“index.html”,
“images/backpack.png”,
“shared/bootstrap/fonts/helvertica.eot”,
“css/fonts/helverticabold.eot”,
“shared/css/astyle.css”,
“js/libs/jquery-ui-1.10.4/jquery-ui.min.js”,
“js/libs/jquery.tipsy.js”,
“js/libs/raphael.js”
因为我想制作一个json文档。这可能吗? 感谢。
答案 0 :(得分:0)
这是find
擅长的任务:
% find folder -type f | sed -e 's,folder/,",' -e 's/$/",/'
您可能能够调整's,folder/,",'
替换,比如说
(cd folder; find . -type f) | sed 's/\(.*\)/"\1",/'
进一步改进是读者的练习!