【问题标题】:How to search files which contain Chinese characters at terminal of Mac?如何在Mac终端搜索包含汉字的文件?
【发布时间】:2020-08-28 04:45:47
【问题描述】:

我有一个Vue.js项目,有一些资源视图包含汉字,我想从终端全部找到。

我试过了,但我的grep 没有-P

grep -R -P '[\p{Han}]' resources

【问题讨论】:

  • 找到了匹配特定字符grep -R $'\u4FDD\u5B58' resources的方法

标签: macos shell unicode terminal grep


【解决方案1】:

找到了pcregrep的解决方案,中文在多个unicode块中,所以这种方式比较简单。

pcregrep -r -n '[^\x00-\x7f]' resources

【讨论】:

    【解决方案2】:

    新版OSX好像不再支持grep -P

    如果您想做最少的工作,请更改:

    $ grep -P 'PATTERN' file.txt
    

    $ perl -nle'print if m{PATTERN}' file.txt
    

    【讨论】:

      猜你喜欢
      • 2014-10-24
      • 2012-09-27
      • 1970-01-01
      • 1970-01-01
      • 2021-02-04
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      • 2021-12-02
      相关资源
      最近更新 更多