開始我在一個文件中的以下數據:刪除字符串從特定字符在python
Neighbor V TblVer InQ OutQ Up/Down State/PfxRcd
10.230.2.91 4 136041 0 0 35w6d 1178
CHN_RAY_901_1AC_CASR903R004# exit
Neighbor V TblVer InQ OutQ Up/Down State/PfxRcd
10.229.5.239 4 890585 0 0 7w5d 1177
10.229.6.239 4 890585 0 0 7w5d 1173
CHN_MAR_905_1AC_CASR903R066# exit
10.229.30.110
我必須刪除從CHN開始的所有行,並且具有等的輸出:
Neighbor V TblVer InQ OutQ Up/Down State/PfxRcd
10.230.2.91 4 136041 0 0 35w6d 1178
Neighbor V TblVer InQ OutQ Up/Down State/PfxRcd
10.229.5.239 4 890585 0 0 7w5d 1177
10.229.6.239 4 890585 0 0 7w5d 1173
10.229.30.110
我已嘗試:
b = ' '.join(word for word in content.split(' ') if not word.startswith('CHN'))
其中content是我的數據我想從中刪除CHN,但它不起作用。
你能提出一些方法來達到這個目的。這可以不使用正則表達式來完成嗎?提前致謝。
嘗試'content.splitlines()',而不是'content.split(」「)' 。 –