简体   繁体   English

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

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

I am trying to find every way to find a string in some text.我试图找到在某些文本中查找字符串的各种方法。 I want to find more ways using grep or sed.我想找到更多使用 grep 或 sed 的方法。 (bear in mind It's case sensitive) (请记住它区分大小写)

  • Every word (strings) containing string "ip" and redirect the output result in /root/found;包含字符串“ip”的每个单词(字符串)并将输出结果重定向到/root/found;
grep ip /usr/share/dict/words/ > /root/found
  • Just words (strings) initiating with "ip" and redirect the output result in /root/found;只是以“ip”开头的单词(字符串)并将输出结果重定向到/root/found;
grep ^ip  /usr/share/dict/words > /root/found
  • Just the word "ip" and redirect the output result in /root/found;只需输入“ip”一词,然后将输出结果重定向到 /root/found;
grep ^ip$ /usr/share/dict/words > /root/found

If you prefer to append output into file /root/found instead using > you have to use >>如果您更喜欢使用>将输出附加到文件 /root/found 中,则必须使用>>

Grep over irrespective of case:无论大小写,都可以使用 Grep:

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

If you want to search all files in sub directories and current directories of /ust/share/dict/words如果要搜索 /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