![](/img/trans.png)
[英]IO#lines is deprecated in Ruby 2.0; how do I iterate line by line?
[英]In Ruby how do I search a string line by line and only show lines that begin with 1
我要執行的操作是將ssh轉換為brctl showmacs br0
在的設備,運行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
和:select
其中x[0] == '1'
。
only_ones = @collection.select{|x| x[0] == '1' }
您可以使用SSHKit運行遠程命令:
on 'ubiquiti.yourdomain.com' do
output = capture(:brctl, 'showmacs br0')
puts output.lines.select{|line| line.start_with? "1"}
end
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.