Here is the working code (intended to be executed with perl -e '<code>' ~/.ssh/config
):
Actual version:
while(<>){if(/^Host (.+)/){$_=$1;foreach $i(/([^ ]+)/g){$h{$i}=1}}}print "$_ " for keys %h;
Identical version with whitespace for reading:
while(<>) {
if(/^Host (.+)/) {
$_=$1;
foreach $i(/([^ ]+)/g) {
$h{$i}=1
}
}
}
print "$_ " for keys %h;
I'm sort of a perl newbie. Is $_=$1
kosher? Is there a straight-forward way to do this with a single regex? Is there anything else I should be doing better here?
Example input output:
For a config file with contents like this:
Host build
HostName build.myserver.com
Host build build.myserver.com
User ubuntu
IdentityFile ~/.ssh/build
Host tunnel
LocalForward 6397 redis.production.com:6379
The output should be (order is not required, trailing space is not required but acceptable):
build build.myserver.com tunnel