【发布时间】:2017-08-19 02:59:33
【问题描述】:
我在我的程序中遇到了问题。我有一个文件列表,我使用此代码对它们进行排序,以找出列表中最常见的 10 种文件类型。
find $DIR -type f | file -b $SAVEFILES | cut -c1-40 | sort -n | uniq -c | sort -nr | head -10
我的输出是这样的
168 HTML document, ASCII text
114 C source, ASCII text
102 ASCII text
33 ASCII text, with very long lines
30 HTML document, UTF-8 Unicode text, with
26 HTML document, ASCII text, with very lon
21 C source, UTF-8 Unicode text
20 LaTeX document, UTF-8 Unicode text, with
15 SVG Scalable Vector Graphics image
12 LaTeX document, ASCII text, with very lo
我想要做的是访问文件类型之前的值并替换它们#。我可以使用 for 循环执行此操作,但首先我可以通过某种方式访问它们。
预期的输出是这样的:
__HTML document, ASCII text : ################
__C source, ASCII text : ###########
__ASCII text : ##########
__ASCII text, with very long lines : ########
__HTML document, UTF-8 Unicode text, with : #######
__HTML document, ASCII text, with very lon: ####
__C source, UTF-8 Unicode text : ####
__LaTeX document, UTF-8 Unicode text, with: ###
__SVG Scalable Vector Graphics image : #
__LaTeX document, ASCII text, with very lo: #
编辑:在我的示例中,# 不代表正确的数字。第一行应该有 168 #,第二行应该有 114 # 等等
【问题讨论】:
-
查看上一个问题的答案:Calling function in awk
-
好吧,我试过了,但没用
-
为什么要删除 bash 标签?
-
您最近的编辑删除了预期的输出,并使答案似乎无法产生现在听起来像您要求的问题。我已经恢复了它。请受邀进一步完善您的问题,但不要让您更难理解您在寻找什么。
标签: dash-shell