here's something to get you started
q. what's not in here?
1. when the search string is found, writing the next ten lines in the array
2. write the new file only if search string is found in the given file
I have a file which contains several lines. Sample content of the file is as below.
OK testmessage email<test@123>
NOK receivemessage email<123@test>
NOK receivemessage email(123@test123)
NOK receivemessage email<abc@test>
i would like to know by scripting will... (10 Replies)
Can someone tell me how I can do this?
e.g:
Say file1.txt contains:
today is monday
the 22 of
NOVEMBER
2010
and file2.txt contains:
the
11th
month
of
How do i replace the word NOVEMBER with (5 Replies)
if the first string matches then print the previous line and current line and also print the following lines if the other string search matches.
Input
------
TranTime 2012 10 12
The Record starts here
Accountnumber: 4632473431274
TxnCode 323
TranID 329473242834
ccsdkcnsdncskd... (7 Replies)
I need to search the file using strings "Request Type" , " Request Method" , "Response Type" and by using result set find the xml tags and convert into a single line?. below are the scenarios.
Cat test
Nov 10, 2012 5:17:53 AM
INFO: Request Type
Line 1.... (5 Replies)
Hi,
I am trying to remove lines once a string is found till another string is found including the start string and end string. I want to basically grab all the lines starting with color (closing bracket). PS: The line after the closing bracket for color could be anything (currently 'more').... (1 Reply)
I am having a text file which is having more than 200 lines.
EX:
001010122 12000 BIB 12000 11200 1200003
001010122 2000 AND 12000 11200 1200003
001010122 12000 KVB 12000 11200 1200003
In the above file i want to search for string KVB and add/replace... (1 Reply)
Dear All
I am having a text file which is having more than 200 lines.
EX:
001010122 12000 BIB 12000 11200 1200003
001010122 2000 AND 12000 11200 1200003
001010122 12000 KVB 12000 11200 1200003
In the above file i want to search for string KVB... (5 Replies)
Hi,
Need your help for this scripting issue I have. I am not really good at this, so seeking your help.
I have a file looking similar to this:
Hello, i am human and name=ABCD.
How are you?
Hello, i am human and name=PQRS.
I am good.
Hello, i am human and name=ABCD.
Good bye.
Hello, i... (12 Replies)
Hi Everyone,
I have a requirement in ksh where i have a set of files in a directory. I need to search each and every file if a particular string is present in the file, delete that line and replace that line with another string expression in the same file.
I am very new to unix. Kindly help... (10 Replies)
Discussion started by: Pradhikshan
10 Replies
LEARN ABOUT DEBIAN
parse::mediawikidump::revisions
Parse::MediaWikiDump::Revisions(3pm) User Contributed Perl Documentation Parse::MediaWikiDump::Revisions(3pm)NAME
Parse::MediaWikiDump::Revisions - Object capable of processing dump files with multiple revisions per article
ABOUT
This object is used to access the metadata associated with a MediaWiki instance and provide an iterative interface for extracting the
indidivual article revisions out of the same. To gurantee that there is only a single revision per article use the
Parse::MediaWikiDump::Revisions object.
SYNOPSIS
$pmwd = Parse::MediaWikiDump->new;
$revisions = $pmwd->revisions('pages-articles.xml');
$revisions = $pmwd->revisions(*FILEHANDLE);
#print the title and id of each article inside the dump file
while(defined($page = $revisions->next)) {
print "title '", $page->title, "' id ", $page->id, "
";
}
STATUS
This software is being RETIRED - MediaWiki::DumpFile is the official successor to Parse::MediaWikiDump and includes a compatibility library
called MediaWiki::DumpFile::Compat that is 100% API compatible and is a near perfect standin for this module. It is faster in all instances
where it counts and is actively maintained. Any undocumented deviation of MediaWiki::DumpFile::Compat from Parse::MediaWikiDump is
considered a bug and will be fixed.
METHODS
$revisions->new
Open the specified MediaWiki dump file. If the single argument to this method is a string it will be used as the path to the file to
open. If the argument is a reference to a filehandle the contents will be read from the filehandle as specified.
$revisions->next
Returns an instance of the next available Parse::MediaWikiDump::page object or returns undef if there are no more articles left.
$revisions->version
Returns a plain text string of the dump file format revision number
$revisions->sitename
Returns a plain text string that is the name of the MediaWiki instance.
$revisions->base
Returns the URL to the instances main article in the form of a string.
$revisions->generator
Returns a string containing 'MediaWiki' and a version number of the instance that dumped this file. Example: 'MediaWiki 1.14alpha'
$revisions->case
Returns a string describing the case sensitivity configured in the instance.
$revisions->namespaces
Returns a reference to an array of references. Each reference is to another array with the first item being the unique identifier of
the namespace and the second element containing a string that is the name of the namespace.
$revisions->namespaces_names
Returns an array reference the array contains strings of all the namespaces each as an element.
$revisions->current_byte
Returns the number of bytes that has been processed so far
$revisions->size
Returns the total size of the dump file in bytes.
EXAMPLE
Extract the article text of each revision of an article using a given title
#!/usr/bin/perl
use strict;
use warnings;
use Parse::MediaWikiDump;
my $file = shift(@ARGV) or die "must specify a MediaWiki dump of the current pages";
my $title = shift(@ARGV) or die "must specify an article title";
my $pmwd = Parse::MediaWikiDump->new;
my $dump = $pmwd->revisions($file);
my $found = 0;
binmode(STDOUT, ':utf8');
binmode(STDERR, ':utf8');
#this is the only currently known value but there could be more in the future
if ($dump->case ne 'first-letter') {
die "unable to handle any case setting besides 'first-letter'";
}
$title = case_fixer($title);
while(my $revision = $dump->next) {
if ($revision->title eq $title) {
print STDERR "Located text for $title revision ", $revision->revision_id, "
";
my $text = $revision->text;
print $$text;
$found = 1;
}
}
print STDERR "Unable to find article text for $title
" unless $found;
exit 1;
#removes any case sensativity from the very first letter of the title
#but not from the optional namespace name
sub case_fixer {
my $title = shift;
#check for namespace
if ($title =~ /^(.+?):(.+)/) {
$title = $1 . ':' . ucfirst($2);
} else {
$title = ucfirst($title);
}
return $title;
}
LIMITATIONS
Version 0.4
This class was updated to support version 0.4 dump files from a MediaWiki instance but it does not currently support any of the new
information available in those files.
perl v5.10.1 2010-12-05 Parse::MediaWikiDump::Revisions(3pm)