Eeba234182bcbd7faed9ff52e233394d

My aim: Print out the regex capture for each line of standard input

Would rather use standard shell commands for use in bash script than going into ruby.

1
2
3
4
5
6
7
regexp = Regexp.new(ARGV[0])

match_index = (ARGV[1] || 1).to_i

while line = $stdin.gets do
  puts regexp.match(line.chomp)[match_index]
end

Refactorings

No refactoring yet !

7c45f63f61e478233f0c2ad3006b178c

michiel

November 6, 2007, November 06, 2007 01:48, permalink

2 ratings. Login to rate!
1
grep -o  regexp filename
Eeba234182bcbd7faed9ff52e233394d

DougBTX

November 7, 2007, November 07, 2007 01:49, permalink

No rating. Login to rate!

Magic, using a variant of:

1
ls | grep -o "[0-9]\{1,\}"

Your refactoring





Format Copy from initial code

or Cancel