如何grep只是将“ip”字符串写入文件?

时间:2015-06-28 15:07:47

标签: regex linux bash sed grep

我试图找到在某些文本中找到字符串的各种方法。我想找到更多使用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

1 个答案:

答案 0 :(得分:1)

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

无论案件如何,我都会哭泣:

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