in reply to Re: How can I find a line in a RTF file?
in thread How can I find a line in a RTF file?

Thanks. I almost have this working. I dont know how the index works in the code above. I need to do more searching for @- and @+.

I'm scanning the documents on a windows OS because the dates will change if I transfer to linux. the documents might also have several pages of text between the "Date of Last Update" and signatures. I'm on a team of a few people trying to determine why policies take so long to get signed. I have not used perl extensively for several years. Thanks for your help. I'll update the page with the code and 2 sample files when I am done.

#!/usr/bin/perl use Modern::Perl; use RTF::TEXT::Converter; my $string; my $object = RTF::TEXT::Converter->new(output => \$string); $object->parse_stream( '..\Policies\Test\000144027.rtf' ); chomp $string; my @string = split("\n", $string); my $number_of_sigs = 0; foreach my $line (@string) { chomp $line; if ($line =~ m/Date of Last Update:(.*)/){ my $date_of_last_update = $1; $date_of_last_update =~ s/^\s+//; print "Date of last update is: $date_of_last_update\n"; } if ($line =~ m/Document #:(.*)/){ print "\nDocument number is $1\n"; } # Sign-Off Approvals if ($line =~/'Sign-Off Approvals'/){ print $line; $number_of_sigs ++; } # next; #next if $line !~ /\w+/; #next if $line =~ /^\_+\/\_+\/\_+$/; #say $line; } print "number of signatures is $number_of_sigs \n";

Replies are listed 'Best First'.
Re^3: How can I find a line in a RTF file?
by james28909 (Deacon) on Aug 10, 2014 at 00:21 UTC
    honestly it shouldnt matter if there are 400 pages between dat and signature. as long as they are all in the same document and there is never another instance of it. also with the code i posted, it shouldnt matter if the dates change at all. they can be 01/01/0001, or 1/1/0001, you can add an extra elsif and add to include if dat is 1/1/01 as well
Re^3: How can I find a line in a RTF file?
by james28909 (Deacon) on Aug 10, 2014 at 00:24 UTC
    and its just a simple pattern match then it will seek so many characters at the beginning or the end of the match. i put in the code i posted @- and @+ to show you how its used. if you want to see how it works, open the file in HxD editor and look on the text side (right side) and compare with the script.