Skip to content

Instantly share code, notes, and snippets.

@masaakif
Created June 19, 2013 01:09
Show Gist options
  • Save masaakif/5810949 to your computer and use it in GitHub Desktop.
Save masaakif/5810949 to your computer and use it in GitHub Desktop.
定形のフォーマットのテキストファイルから、MarketID、ExchangeIDを抜粋し、重複しないようにして表示する.
require 'set'
# source format is
# +----------+------------+-----------+
# | MarketID | ExchangeID | SedolCode |
# +----------+------------+-----------+
# | caequ | XTSX | 2000075 |
# | clequ | XSGO | 2000257 |
#
# Output format is
# 1 \t caequ \t XTSX
# 2 \t clequ \t XSGO
exs = Set.new
["sedol.1","sedol.2","sedol.3"].each do |fn|
l = 0
open(fn).each do |line|
l = l + 1
next if l < 5
break if line[0] == '+' and l > 10
ex = "#{line[2..6]}\t#{line[13..16]}"
exs.add ex
end
end
l = 0
exs.sort.each do |ex|
l = l + 1
puts "#{l}\t#{ex}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment