# Problems reading a text file with unusual encoding

**URL:** <https://www.ruby-forum.com/t/problems-reading-a-text-file-with-unusual-encoding/172456>\
**Category:** Ruby\
**Created:** [July 21, 2009, 9:34pm UTC](https://www.ruby-forum.com/t/problems-reading-a-text-file-with-unusual-encoding/172456 "2009-07-21T21:34:23Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![owossoborn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f19dbf/32.png) [@owossoborn](https://www.ruby-forum.com/u/owossoborn)\
**Post date:** [July 21, 2009, 9:34pm UTC](https://www.ruby-forum.com/t/problems-reading-a-text-file-with-unusual-encoding/172456/1 "2009-07-21T21:34:23Z")

</div>

I have a pcap file that I simply changed the file extension to text on.  
It can be seen here:

[http://69.4.224.185/output.txt](http://69.4.224.185/output.txt)

When I try to load the file into Ruby, some parts of it come out, while  
others don’t.

For example:

input = File.readlines(‘output.txt’)

input = input.to\_s

proof = input.scan(/challenge/)

proof =\> challenge

Challenge is written in the file and it can be scanned for  
appropriately. However, other normally written words (there’s a line  
that says bdticket later on) can not be parsed. I realize this isn’t the  
most elegant way of going about this, but this is the only format I can  
get this file in, and if I open the file in notepad I can see the  
following:

bdTicket\WQmS/

But when I scan for bdTicket, nothing comes up.

Anyone have any ideas how I can get around this?

Any help is appreciated!

---

<div class="post-metadata">

**Author:** ![owossoborn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/o/f19dbf/32.png) [@owossoborn](https://www.ruby-forum.com/u/owossoborn)\
**Post date:** [July 22, 2009, 2:53am UTC](https://www.ruby-forum.com/t/problems-reading-a-text-file-with-unusual-encoding/172456/2 "2009-07-22T02:53:59Z")

</div>

Hi,

2009/7/22 Randy G. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid):

> input = File.readlines(‘output.txt’)  
> most elegant way of going about this, but this is the only format I can  
> get this file in, and if I open the file in notepad I can see the  
> following:
> 
> bdTicket\WQmS/
> 
> But when I scan for bdTicket, nothing comes up.
> 
> Anyone have any ideas how I can get around this?
> 
> Any help is appreciated!

I guess your OS is Windows.

Try  
input = File.open(‘output.txt’,‘rb’).readlines  
instead of  
input = File.readlines(‘output.txt’)

Regards,

Park H.
