我想過濾檔案的行,只取那些說阿爾茨海默氏癥并且又匹配 chrM 和 chrY 模式的行。如何同時過濾三種模式?我一直無法找到答案,我剛剛這樣做了:
awk '/Alzheimer/ {print $0}' genemap2.txt
我試過:
awk '/Alzheimer/chrM/chrY/ {print $0}' genemap2.txt
awk '/["Alzheimer"chrM"]/{print $0}' genemap2.txt
你能幫我么?
uj5u.com熱心網友回復:
這個怎么樣:
awk '/Alzheimer/ && /chrM/ && /chrY/ {print $0}' genemap2.txt
約的好處awk這里是,匹配單詞的順序并不重要。如果你想使用順序,試試這個:
awk '/Alzheimer.*chrM.*chrY/ {print $0}' genemap2.txt
uj5u.com熱心網友回復:
最簡單的過濾方法是使用grep. 如果要根據不同條件進行過濾,可以執行以下操作:
使用 AND-“子句”:
output | grep "cond1" | grep "cond2" | grep "cond3"
這將只顯示輸出的行,包含cond1AND cond2AND cond3。
使用 OR-“子句”:
output | grep -E "cond1|cond2|cond3"
的-E代表“擴展的grep”,且輸出的這顯示線,含有cond1OR cond2OR cond3。
如果您想知道是否可以將 AND 和 OR 結合起來,是的,它是:
output | grep "cond1" | egrep "cond2|cond3"
egrep是 的別名grep -E,此示例顯示包含cond1AND 其他條件之一cond2或 OR的輸出行cond3。
您還可以grep使用-v開關反轉,這將顯示不包含...的行
uj5u.com熱心網友回復:
假設你有這個輸入 genemap2.txt(5 行):
$ cat genemap2.txt
1 I want to filter the lines of a file,
2 taking only those
3 that say Alzheimer's and that in turn match the chrM and chrY patterns.
4 Or Alzheimer's chrM.
5 Or Alzheimer's chrY.
這是(下面幾行)您要找的嗎?
awk '/Alzheimer/ && /chr(M|Y)/' genemap2.txt
3 that say Alzheimer's and that in turn match the chrM and chrY patterns.
4 Or Alzheimer's chrM.
5 Or Alzheimer's chrY.
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/351550.html
下一篇:如何在bash中修剪字串變數
