Click here to get back home

Search a Text File for a String, Return String to Function

 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 a Text File for a String, Return String to Function cl 07-29-2006
Get Chitika Premium
Posted by cl on July 29, 2006, 12:19 pm
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 Dr.Ruud on July 29, 2006, 6:14 pm
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 for string and return file name November 17, 2004, 1:13 am
write a function to return an evaluated string using eval, Help! December 14, 2005, 4:29 pm
Help: String search in Windows 2000 doesn't find text in WindowsXP: MS Word document November 27, 2005, 9:13 am
Search for a string in a binary file November 19, 2006, 9:25 am
Truncating text from a string with beginning text from another string March 23, 2007, 1:44 pm
Reading UTF-8 string from file with read() function. August 31, 2004, 10:38 am
string substitution for a file, without replacing partial string? October 22, 2006, 1:24 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
Simple string search November 1, 2007, 10:57 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap