How can I extract numeric data from a text file?

Here's a short program that gives you the meat of the problem, and you can add the rest of it: while( ) { s|http://. */\d+/(\d+)/(\d+). *?

Jpg|php? Id=$1$2|; print; } This is very close to the command-line program the handles the looping and printing for you with the -p switch (see the perlrun documentation for the details): perl -pi. Old -e 's|http://.

*/\d+/(\d+)/(\d+). *? Jpg|php?

Id=$1$2|' inputfile > outputfile.

I didn't know whether to answer according to what you described ("last 6 digits") or just assume that it all fits the pattern you showed. So I decided to answer both ways. Here is a method that can handle lines more diverse than your examples.

Use FileHandle; my $jpeg_RE = qr{ (.*? ) # Anything, watching out for patterns ahead \s+ # At least one space (?> " rel="nofollow"> ) # Once we match "" rel="nofollow">" we're onto the next section \S*? # Any non-space, watching out for what follows ( (?: \d+ / )* # At least one digit, followed by a slash, any number of times \d+ # another group of digits ) # end group \D*?

# Any number of non-digits looking ahead \. Jpg # literal string '. Jpg' \s+ # At least one space (.*) # The rest of the line }x; my $infile = FileHandle->new( "new( ">$file_out" ); while ( my $line = ) { my ( $pre_text, $digits, $post_text ) = ( $line =~ m/$jpeg_RE/ ); $digits =~ s/\D//g; $outfile->printf( "$pre_text php?

Id=%s $post_text\n", substr( $digits, -6 )); } $infile->close(); However, if it's just as regular as you show, it gets a lot easier: use FileHandle; my $jpeg_RE = qr{ (?> \Q" rel="nofollow">pics1.riyaj. Com/thumbs/\E ) \d{3} / ( \d{3} ) / ( \d{3} ) \S*? \.

Jpg }x; my $infile = FileHandle->new( "new( ">$file_out" ); while ( my $line = ) { $line =~ s/$jpeg_RE/php? Id=$1$2/g; $outfile->print( $line ); } $infile->close().

I didn't know whether to answer according to what you described ("last 6 digits") or just assume that it all fits the pattern you showed. So I decided to answer both ways.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions