in reply to Re: One liner: remove ssh keys with quotemeta
in thread One liner: remove ssh keys with quotemeta

As per my previous reply, discarding the regex and just using string equality:

$ cat b1.bak ssh-rsa CCCC/DDDD/knMQ== user@host2.f.q.d.n ssh-rsa AAAA/BBBB/kPW+Yi9yZ7Kh0mL/knMQ== user@host.f.q.d.n $ perl -lne 'print unless $_ eq q(ssh-rsa AAAA/BBBB/kPW+Yi9yZ7Kh0mL/kn +MQ== user@host.f.q.d.n)' b1.bak ssh-rsa CCCC/DDDD/knMQ== user@host2.f.q.d.n

Replies are listed 'Best First'.
Re^3: One liner: remove ssh keys with quotemeta
by Anonymous Monk on Dec 02, 2019 at 21:43 UTC
    Hey mate,

    thanks for that.
    It turns out you were right and in fact we don't need to do all the escapes / quotemeta stuff !
    I can't believe it's that simple - I was convinced the previous guy was on the right track...

    To be fair, I've done a lot of Perl programming in the past, but almost never one liners like this (especially also having to worry about passing it through the shell etc).

    Final code (inside puppet)
    exec { "/usr/bin/perl -i -lne 'print unless \$_ eq q($line)' '${file} +'":
    BTW, that -l switch is magic :)

    Cheers
    Chris