需要幫助。我一直在尋找一整天沒有找到具體到我需要的解決方案。根據字符串查找並刪除文件中的行但保留最後一次出現
在一個文件中:
Lots
of
other
lines
...
...
# [email protected] ..........1323 <- Do not include '# Client=HOSTNAME'
# [email protected] ..........123123 <- Do not include '# Client=HOSTNAME'
[email protected] ....rndChars.... <- delete line
[email protected] ....rndChars.... <- delete line
[email protected] ....rndChars.... <- delete line
[email protected] ....rndChars.... <- delete line
[email protected] ....rndChars.... <- keep last occurrence
[email protected] ....rndChars.... <- keep last occurrence
[email protected] ....rndChars.... <- delete line
[email protected] ....rndChars.... <- delete line
[email protected] ....rndChars.... <- keep last occurrence
...
...
more
lines
我要找到匹配的所有行「客戶端=」以上,刪除該行除了最後occurrance。問題是我永遠不知道主機名是什麼。
輸出應該是:
Lots
of
other
lines
...
...
# [email protected] ..........1323 <- Do not include '# Client=HOSTNAME'
# [email protected] ..........123123 <- Do not include '# Client=HOSTNAME'
[email protected] ....rndChars.... <- keep last occurrence
[email protected] ....rndChars.... <- keep last occurrence
[email protected] ....rndChars.... <- keep last occurrence
...
...
more
lines
提前THX。
你嘗試過這麼遠嗎? –