需要帮助。我一直在寻找一整天没有找到具体到我需要的解决方案。根据字符串查找并删除文件中的行但保留最后一次出现
在一个文件中:
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。
你尝试过这么远吗? –