在Ruby中,如何逐行搜索字符串并只显示以1开头的行

在Ruby中,如何逐行搜索字符串并只显示以1开头的行,ruby,ssh,Ruby,Ssh,我想做的是通过ssh连接到ubiquiti设备,运行brctl showmacs br0并仅检索本地端口1上的mac地址,例如: 1 d4:ca:6d:ec:aa:fe no 0.05 将打印/放入/写入文件,因为它以1开头,而: 2 4c:5e:0c:d5:ba:95 no 38.62 不会。字符串响应[];因此,您可以在集合@collection中选择x[0]=“1”所在的位置 您可以使

我想做的是通过ssh连接到ubiquiti设备,运行brctl showmacs br0并仅检索本地端口1上的mac地址,例如:

1     d4:ca:6d:ec:aa:fe       no                 0.05
将打印/放入/写入文件,因为它以1开头,而:

2     4c:5e:0c:d5:ba:95       no                38.62
不会。

字符串响应[];因此,您可以在集合@collection中选择x[0]=“1”所在的位置

您可以使用来运行远程命令:

on 'ubiquiti.yourdomain.com' do
  output = capture(:brctl, 'showmacs br0')
  puts output.lines.select{|line| line.start_with? "1"}
end

将来,请包含您的代码。您是否也在询问如何通过ssh自动化此操作?
on 'ubiquiti.yourdomain.com' do
  output = capture(:brctl, 'showmacs br0')
  puts output.lines.select{|line| line.start_with? "1"}
end