簡體   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