Click here to get back home

simple perl regex question

 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
simple perl regex question steve.logan@gmail.com 08-20-2007
Get Chitika Premium
Posted by steve.logan@gmail.com on August 20, 2007, 5:27 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 Mirco Wahab on August 20, 2007, 5:23 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 Mirco Wahab on August 20, 2007, 5:25 pm
Please log in for more thread options
steve.logan@gmail.com wrote:
> Here's where I'm at - it runs ok, but the file isn't being updated:
> perl -pi -e 's/\/([0-9])([;])\//2007083100;/g' domain.com.db
> I think I'm close here - maybe?

Yes, hairs width (imho). But I've seen zone files with a \s in front
of the ';' ...

$> perl -i -pe 's/(?<!\d)\d(?=\s*;)/2007083100/g' domain.com.db

Regards

M.

Posted by steve.logan@gmail.com on August 20, 2007, 6:16 pm
Please log in for more thread options
Wow - I need to read up on what some of that stuff does.

Thank you - it works like a charm!!

> steve.lo...@gmail.com wrote:
> > Here's where I'm at - it runs ok, but the file isn't being updated:
> > perl -pi -e 's/\/([0-9])([;])\//2007083100;/g' domain.com.db
> > I think I'm close here - maybe?
>
> Yes, hairs width (imho). But I've seen zone files with a \s in front
> of the ';' ...
>
> $> perl -i -pe 's/(?<!\d)\d(?=\s*;)/2007083100/g' domain.com.db
>
> Regards
>
> M.



Similar ThreadsPosted
Simple REGEX-Question January 21, 2006, 6:39 am
Simple regex question November 27, 2006, 6:06 pm
RegEx Woes! Please Help, Simple Question May 1, 2005, 1:35 pm
Re: simple perl question September 18, 2008, 10:14 pm
Question about simple databases in Perl October 16, 2007, 10:30 am
regex - to simple to see? November 16, 2004, 10:24 pm
Simple REGEX February 3, 2007, 6:40 am
simple regex June 5, 2007, 12:33 pm
missing simple regex January 23, 2007, 2:36 pm
Q on regex of LWP::Simple data March 1, 2007, 11:57 pm

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap