0

I have a EBCDIC file that was generated from a Mainframe and will need to convert it to ASCII for data processing.
Any help would be appreciated.

PackedUp
  • 369
  • 5
  • 16
  • It's better to [provide a simple example and expected result](http://stackoverflow.com/help/mcve). – Yu Hao Jan 13 '15 at 01:29
  • 2
    possible duplicate of [How do I do ASCII to EBCDIC translation in Ruby?](http://stackoverflow.com/questions/4718324/how-do-i-do-ascii-to-ebcdic-translation-in-ruby) – Swiss Jan 13 '15 at 01:32
  • This question is indeed a duplicate of that; the answers were a bit outdated (depending on which version you're using) but I have updated [the appropriate answer](http://stackoverflow.com/a/4718545/1735262). – Reinstate Monica -- notmaynard Jan 13 '15 at 16:00
  • @iamnotmaynard 2.0.0-p247 :002 > x=Iconv.new('EBCDIC-US','ASCII') Iconv::InvalidEncoding: invalid encoding ("EBCDIC-US", "ASCII") from (irb):2:in `initialize' – PackedUp Jan 13 '15 at 16:06
  • Weird... it works for me. Did you install the gem, or are you just using the library? It appears that maybe 2.0.0 still has the library. – Reinstate Monica -- notmaynard Jan 13 '15 at 16:11
  • It seems to work for me on Ruby 2.2.0 (though I don't have any EBCDIC files to really test it on). It might be worthwhile to upgrade. – Reinstate Monica -- notmaynard Jan 13 '15 at 16:12

1 Answers1

0

Since [Ruby 2.3 the EBCDIC-encoding is available][1]:

Encoding

new Encoding::IBM037 (alias ebcdic-cp-us; dummy)

So this should work:

src = 'out_26877296.tst'
content = File.read(src, encoding: 'IBM037:ASCII')
knut
  • 27,320
  • 6
  • 84
  • 112