如何在所有的.py .txt .cpp文件 中grep “abc”和“123”两个字符串?

方紫涵 2012-09-06 05:34:51
如何在所有的.py .txt .cpp文件 中grep “abc”和“123”两个字符串?
...全文
148 7 打赏 收藏 转发到动态 举报
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
freetstar 2012-09-07
  • 打赏
  • 举报
回复
grep -R '(abc|123)' *.cpp *.py *.txt
mymtom 2012-09-07
  • 打赏
  • 举报
回复
find . -name "*.py" -o -name "*.txt" -o "*.cpp" | xargs grep -E "abc|123"
方紫涵 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]

grep -Ern '(abc|123)' *.cpp *.py *.txt
grep -Ern '(abc|123)' `find . -regextype posix-egrep -regex '.*(cpp|txt|py)'`
[/Quote]

ks$ grep -Ern '(String|main)' *.cpp *.java ./
grep: *.cpp: 没有那个文件或目录
grep: *.java: 没有那个文件或目录
./opt/emoji/EmojiFactory.h:90: // The ownership of the instance remains to this class, so users must not
./opt/emoji/EmojiFactory.h:97: // The ownership of the instance remains to this class, so users must not


好像不对阿。。?
mymtom 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 5 楼 的回复:]

引用 3 楼 的回复:

find . -name "*.py" -o -name "*.txt" -o "*.cpp" | xargs grep -E "abc|123"

Mode$ find . -name "*.py" -o -name "*.txt" -o "*.cpp" | xargs grep -E "abc|123"
find: 路径必须在表达式之前: *.cpp
……
[/Quote]
不好意思! 手误了,试试下面这个:
find . -name "*.py" -o -name "*.txt" -o -name "*.cpp" | xargs grep -E "abc|123"
方紫涵 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 的回复:]

grep -R '(abc|123)' *.cpp *.py *.txt
[/Quote]
Mode$ grep -R '(abc|123)' *.cpp *.py *.txt
grep: *.cpp: 没有那个文件或目录
grep: *.py: 没有那个文件或目录
grep: *.txt: 没有那个文件或目录

方紫涵 2012-09-07
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

find . -name "*.py" -o -name "*.txt" -o "*.cpp" | xargs grep -E "abc|123"
[/Quote]
Mode$ find . -name "*.py" -o -name "*.txt" -o "*.cpp" | xargs grep -E "abc|123"
find: 路径必须在表达式之前: *.cpp
用法: find [-H] [-L] [-P] [-Olevel] [-D help|tree|search|stat|rates|opt|exec] [path...] [expression]


ForestDB 2012-09-06
  • 打赏
  • 举报
回复
grep -Ern '(abc|123)' *.cpp *.py *.txt
grep -Ern '(abc|123)' `find . -regextype posix-egrep -regex '.*(cpp|txt|py)'`

19,612

社区成员

发帖
与我相关
我的任务
社区描述
系统使用、管理、维护问题。可以是Ubuntu, Fedora, Unix等等
社区管理员
  • 系统维护与使用区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧