Skip to content

Instantly share code, notes, and snippets.

Created April 10, 2015 23:01
Show Gist options
  • Save anonymous/a2bd973cfd7e62ce7e2a to your computer and use it in GitHub Desktop.
Save anonymous/a2bd973cfd7e62ce7e2a to your computer and use it in GitHub Desktop.
###INPUT (tab-separated text file)
CA 12
CA 11
CA 10
AL 11
AL 19
AK 20
AR 28
AK 11
GA 10
GA 32
###OUTPUT (text file)
update _ca set active = 0 where id in(12,11,10)
update _al set active = 0 where id in(11,19)
update _ak set active = 0 where id in(20,11)
update _ar set active = 0 where id in(28)
update _ga set active = 0 where id in(10,32)
@baweaver
Copy link

File
  .read(my_file)
  .lines
  .map(&:split)
  .group_by(&:first)
  .map { |g, v| [g, v.map(&:last)] }
  .to_h
  .map { |k, v| "update_#{k.downcase} set active = 0 where id in (#{v.join(',')})" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment