下面是perl脚本
my $var="
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
da:be:66:35:0e:47:0f:60:f1:70:a4:43:ff:39:da:65.
Please contact your system administrator.
Add correct host key in /home/PCS/.ssh/known_hosts to get rid of this message.
Offending key in /home/PCS/.ssh/known_hosts:144
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg00-lscratch 7288301568 6079377352 1208924216 84% /scratch
";
$var =~ s/.+Filesystem/Filesystem/g;
print "$var\n";
打印的是($var值):
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that the RSA host key has just been changed.
The fingerprint for the RSA key sent by the remote host is
da:be:66:35:0e:47:0f:60:f1:70:a4:43:ff:39:da:65.
Please contact your system administrator.
Add correct host key in /home/PCS/.ssh/known_hosts to get rid of this message.
Offending key in /home/PCS/.ssh/known_hosts:144
Password authentication is disabled to avoid man-in-the-middle attacks.
Keyboard-interactive authentication is disabled to avoid man-in-the-middle attacks.
Filesystem22 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg00-lscratch 7288301568 6079377352 1208924216 84% /scratch
替换似乎不起作用。
据我所知, $var 应该打印以下内容,但事实并非如此。怎么办呢?这个替换有什么问题吗?
Filesystem 1K-blocks Used Available Use% Mounted on
/dev/mapper/vg00-lscratch 7288301568 6079377352 1208924216 84% /scratch
.
匹配 LF 以外的任何字符。但你想匹配任何字符。您可以使用 /s
来做到这一点。
s/.+Filesystem/Filesystem/sg
澄清
Filesystem
出现在行首:
s/.+^Filesystem/Filesystem/msg
防止匹配失败时不必要的回溯:
s/\A.+^Filesystem/Filesystem/msg
防止重复:
s/\A.+^(?=Filesystem)//msg