簡體   English   中英

如何獲得沒有這些字符的單詞?

[英]How do I get the words without these characters?

我只想從文本文件1.txt獲取不包含字母abc的單詞,並將其導出到2.txt ,但這不會返回任何內容:

grep -o [^abc]*$ 1.txt > 2.txt

如何獲得不包含abc的單詞?

使用GNU grep,您可以使用

grep -w -o '[^abc]*' 1.txt > 2.txt

man的相關作品是:

  -w, --word-regexp
          Select only those lines containing matches that form whole words...

  -o, --only-matching
          Print  only  the  matched  (non-empty)  parts  of  a  matching line...

嘗試這個:

grep -w -o -P '[^abc\s]*' 1.txt > 2.txt

因此,在“單詞”中間也不允許使用空格。

我也僅包括了-P標志,以便將正則表達式解釋為Perl並允許\\ s占位符。

 -P, --perl-regexp
          Interpret PATTERN as a Perl regular expression.

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM