Prepare for your Next Interview
This is a discussion on How to match multiline when reading input file line by line within the PERL forums, part of the Web Development category; Dear all, I am doing QC Tool for XML Document. I need to generate error log with error(including line#,Col#). How I am following is, Code: while($_ =~ m/&...
|
|||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
|
|||
|
Dear all,
I am doing QC Tool for XML Document. I need to generate error log with error(including line#,Col#). How I am following is, Code:
while($_ =~ m/<h><\/h>\n<p>/msg)
{
print "Err/line/Col";
}
It's not working. It matches upto <h><\/h>\n only. Please suggest how to proceed. Thanks in Advance. vishwa Ram. |
| Sponsored Links |
|
|||
|
Re: How to match multiline when reading input file line by line
hi,
the below attached program resolves your following issue. <tb> Het blijvend beeld der Hollandse Kunst|1 De Bijbel in Holland's Schilder-cultuur|25 </tb> Some other text Output file: Some other text <tb> <r><ce>Het blijvend beeld der Hollandse Kunst</ce><ce>1</ce></r> </tb> Some other text ########################################## #!/usr/bin/perl use strict; use IO::File; print "\n File operations"; my $source_file="/home/myprog/oldfile"; my $destination_file="/home/myprog/newfile"; my $input = IO::File->new("< $source_file") # open file in read mode or die "Couldn't open $source_file for reading: $!\n"; my $output = IO::File->new("+> $destination_file") # open file for write mode or die "Couldn't open $destination_file for reading: $!\n"; my $line; while (defined($line = $input->getline())) { chomp($line); if ( $line =~ /^<tb>/ ) # if $line contain <tb> then only execute following block of code { print $output "<tb> \n"; # write <tb> tag in output file while ($line !~ /<\/tb>/) { $line=$input->getline(); # get next line of STDOUT->print($line) if ($line =~ /^\w*\|*/); if ($line =~ s/\|/<\/ce><ce>/g) { # search string | and replace with <\ce><ce> chomp($line); print $output "<r><ce>$line</ce></r> \n" #final string present in between <tb>...</tb> } } print $output "</tb>\n"; # write close </tb> tag in output file } else { print $output "$line \n" # write rest of the code as it is. } } $input->close(); $output->close(); ########################## output: oldfile ===> HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH <tb> Het blijvend beeld der Hollandse Kunst|1 De Bijbel in Holland's Schilder-cultuur|25 </tb> TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT and newfile ===> HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH <tb> <r><ce>Het blijvend beeld der Hollandse Kunst</ce><ce>1</ce></r> <r><ce>De Bijbel in Holland's Schilder-cultuur</ce><ce>25</ce></r> </tb> TTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTTT Last edited by amitbhosale : 02-07-2008 at 07:47 AM. |
![]() |
|
| Thread Tools | |
| Display Modes | |
|
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Line to ground fault occurs on a transmission line | ykbharat | Electrical Engineering | 2 | 07-29-2008 07:02 AM |
| Append the result of another shell script to the last line of a file | swaroopa | Unix/Linux | 1 | 06-26-2007 04:29 PM |
| Option in Unix for line by line execution | sarith | Unix/Linux | 1 | 05-28-2007 12:22 PM |
| Second line in a MsgBox | Geek_Guest | QTP | 3 | 04-19-2007 12:32 PM |
| How to continue to next line | timmy | Unix/Linux | 1 | 08-20-2006 12:16 AM |