繁体   English   中英

如何只将字符串“ip”grep 到文件中?

[英]How to grep just strings "ip" into a file?

我试图找到在某些文本中查找字符串的各种方法。 我想找到更多使用 grep 或 sed 的方法。 (请记住它区分大小写)

  • 包含字符串“ip”的每个单词(字符串)并将输出结果重定向到/root/found;
grep ip /usr/share/dict/words/ > /root/found
  • 只是以“ip”开头的单词(字符串)并将输出结果重定向到/root/found;
grep ^ip  /usr/share/dict/words > /root/found
  • 只需输入“ip”一词,然后将输出结果重定向到 /root/found;
grep ^ip$ /usr/share/dict/words > /root/found

如果您更喜欢使用>将输出附加到文件 /root/found 中,则必须使用>>

无论大小写,都可以使用 Grep:

grep -i "ip" /ust/share/dict/words >> /root/found 

如果要搜索 /ust/share/dict/words 的子目录和当前目录中的所有文件

find /ust/share/dict/words -name "*" -exec grep "ip"  '{}' \; -print  >> /root/found 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM