LINUX.ORG.RU

История изменений

Исправление theNamelessOne, (текущая версия) :

Можно использовать вариант с negative lookahead assertion:

╓─[nameless@localhost]┅┅(/tmp)
╙─[%> cat script.rb 
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

while gets
  puts "a = #{$1} b = #{$2}" if $_ =~ /^(?![;#])(.*?)\s+(.*)/
end
╓─[nameless@localhost]┅┅(/tmp)
╙─[%> ruby script.rb file.txt 
a = 1 b = 2
a = 3 b = 4
a = 5 b = 6
a = 7 b = 8
╓─[nameless@localhost]┅┅(/tmp)
╙─[%> ruby -ne 'puts "a = #{$1} b = #{$2}" if $_ =~ /^(?![;#])(.*?)\s+(.*)/' file.txt 
a = 1 b = 2
a = 3 b = 4
a = 5 b = 6
a = 7 b = 8

Исходная версия theNamelessOne, :

Можно использовать вариант с negative lookahead assertion:

╓─[nameless@localhost]┅┅(/tmp)
╙─[%> cat script.rb 
#!/usr/bin/env ruby
# -*- coding: utf-8 -*-

while gets
  puts "a = #{$1} b = #{$2}" if $_ =~ /^(?![;#])(.*?)\s+(.*)/
end
╓─[nameless@localhost]┅┅(/tmp)
╙─[%> ruby script.rb < file.txt 
a = 1 b = 2
a = 3 b = 4
a = 5 b = 6
a = 7 b = 8
╓─[nameless@localhost]┅┅(/tmp)
╙─[%> ruby -ne 'puts "a = #{$1} b = #{$2}" if $_ =~ /^(?![;#])(.*?)\s+(.*)/' file.txt 
a = 1 b = 2
a = 3 b = 4
a = 5 b = 6
a = 7 b = 8