Click here to get back home

Search for a string in a binary file

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
Search for a string in a binary file EF1 11-19-2006
Get Chitika Premium
Posted by EF1 on November 19, 2006, 9:25 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Sherm Pendley on November 19, 2006, 9:56 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Similar ThreadsPosted
search and replace in a binary file July 22, 2006, 8:56 am
Search a Text File for a String, Return String to Function July 29, 2006, 12:19 pm
Search for string and return file name November 17, 2004, 1:13 am
Need Search::Binary examples June 24, 2006, 5:52 pm
In perl 5.10, is $needle ~~ @haystack binary search? January 16, 2008, 3:42 am
how to convert binary to string? March 1, 2007, 7:20 pm
Obtaining length of binary string December 3, 2004, 1:51 pm
use binary operator on ascii text string June 23, 2006, 2:08 pm
How to search a string in a given line February 7, 2006, 4:12 am
Perl String Search April 19, 2006, 11:19 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap