[英]Use grep to find strings at the beginning of a line or after a delimiter in Git Bash for Windows
[英]constructing regex to find lines not beginning with certain strings with grep in bash
我試圖提出一個正則表達式,將匹配所有不以
10[TAB]A
要么
M10....
並在bash中使用ggrep。
有這樣的事情:
^(^(10\tA|M10*))
但這顯然是錯誤的
非常感謝您的幫助
使用-v
選項:
grep -v '^10\tA\|^M10' /path/to/file
grep -Ev '^10\tA|^M10' /path/to/file
使用-v
選項,它將打印不匹配的行。
注意: \\t
將不起作用。 將其輸入為真實的制表符(按Ctrl + v , Tab )。
您可以使用以下grep命令。
grep -P '^(?!10\tA|M10)' file
(?!10\\tA|M10)
此否定的前瞻斷言,起始錨點(即行的開頭)之后的字符串將不是10
tab A或M10
。 如果一行滿足此條件,則匹配將發生在該對應行的開頭。 因此導致打印這些行。
AWK方式
awk '!/^(10\tA|M10)/' file
或者如果您想使用grep
grep -Ev '^(10 A|M10)' file
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.