本文共 655 字,大约阅读时间需要 2 分钟。
# test.rb#!/usr/bin/env rubywhile (line = STDIN.gets) line.chomp! next unless line =~ /^Hello\s+(\w+)/i puts "name: #{$1}"end
# test.txthello worldHello Lookingdfdhello Jack
[root@master ruby_learning]# cat test.txt | ruby test.rbname: worldname: Lookingname: Jack
-----------------------------------------------------------------------------------------------------------------
# test.rb#!/usr/bin/env rubywhile (line = gets) line.chomp! next unless line =~ /^Hello\s+(\w+)/i puts "name: #{$1}"end
# test.txthello worldHello Lookingdfdhello Jack
[root@master ruby_learning]# ruby test.rb test.txt name: worldname: Lookingname: Jack
转载地址:http://unjqi.baihongyu.com/