How can I extract the data and replace it with new code and store that as new text?

I am trying to extract the last six url numbers in each line of the source text and add it in other code that needs to be added to the result text. It is also necessary to remove some code for each line from the original text and replace it with new code in the result text.

login http://riyajr.googlepages.com/original.txt

Output http://riyajr.googlepages.com/result.txt

Is there any software that can accomplish the above task? Please help me with any other options. It would be great if someone could provide me with a complete script code that could accomplish the above tasks.

0


source to share


2 answers


Yes many. This is a basic application for any scripting language - Perl or Python or ...



+2


source


PHP:

$infile = "in.txt";
$outfile = "out.txt";

foreach (file($url) as $line)
{

    //extract last 6 chars
    $chars = substr($line, -6);

    // append the last 6 chars to a outfile
    file_put_contents($outfile, "$chars\n", FILE_APPEND);
}

      



Note that this does not do any regex to determine if the last 6 characters are a number, which it just blindly grabs.

Get a good script book!

0


source







All Articles