2013-03-19 19 views
0

我試圖使用sed來替換TSV文件中的一些文本,但我堅持使用正則表達式。用Sed找到正確的正則表達式

這裏是一個行的一個示例:

0 NA intron (NR_045393, intron 2 of 2) intron (NR_045393, intron 2 of 2) 1089 

我想intron更換,爲了得到:

0 NA intron intron 1089 

要匹配的模式可以是這樣的內含子(NM_001081221, intron 1 of 20)intron (NM_144536, intron 5 of 15)

我試圖替換模式如下,但我努力得到這個權利

sed -i 's/intron.(\([a-zA-Z0-9\/_]\+\)\/,\s[a-zA-Z]\s[0-9]\s[a-z]\s[0-9])/intron/g' test 

回答

1

如果你只是想去掉括號什麼,只是用

sed -e 's/([^)]*)//g' 

還去除左括號前面的空間,將其添加到正則表達式:

sed -e 's/ ([^)]*)//g' 
0

試試這個:

sed -E -i 's/intron \([A-Z0-9_]+, intron [0-9]+ of [0-9]+\)/intron/g' test 
+0

非常感謝。我不知道我可以使用空格而不是\ s – 2013-03-19 16:24:58