【问题标题】:Count occurrence of files with an odd number characters in the filename计算文件名中包含奇数字符的文件的出现次数
【发布时间】:2014-02-12 06:57:01
【问题描述】:

我正在尝试编写一个脚本来计算系统中所有名称中包含奇数个字符的文件,只有名称而不是扩展名。 有人可以帮助我吗? 我已经这样做了,但它不起作用

find /usr/lib -type f | cut -f 1 -d '.' | rev | cut -f 4 -d '/' | rev | wc -m 

用这个我计算所有文件的所有字符,但是我如何计算一个文件的字符数?

【问题讨论】:

  • 提供一些您想查找的文件名示例。
  • 谢谢你们,mockinterface sol对我来说很容易
  • 如果有适合您的答案,请接受和/或投票,请参阅meta.stackexchange.com/questions/5234/…

标签: shell command debian wc


【解决方案1】:

下面的awk 命令将打印出名称中包含奇数个字符的文件的数量。

find /usr/lib -type f | awk -F/ '{gsub(/\.[^\.]*$/,"",$NF);if(length($NF)%2!=0)i++}END{print i}'

【讨论】:

    【解决方案2】:

    打印所有奇数个字符的文件名,

    find /usr/lib -type f | xargs -i basename {} | cut -d . -f 1 | grep -Pv '^(..)+$'
    

    管道到wc 进行计数。

    【讨论】:

      猜你喜欢
      • 2013-12-23
      • 1970-01-01
      • 1970-01-01
      • 2010-12-08
      • 1970-01-01
      • 1970-01-01
      • 2016-04-28
      • 1970-01-01
      相关资源
      最近更新 更多