我试图找到在某些文本中找到字符串的各种方法。我想找到更多使用grep或sed的方法。 (请记住这是区分大小写的)
grep ip /usr/share/dict/words/ > /root/found
grep ^ip /usr/share/dict/words > /root/found
grep ^ip$ /usr/share/dict/words > /root/found
答案 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