in reply to How can I find a line in a RTF file?
use File::Slurp; my $file = read_file( "file.rtf" ); $match = "Date of Last Update: "; if ($file =~ /$match/){ open my $file, "<", "file.rtf"; my $startpos = "@-"+2; #if date is 8 chars then change to "@-"+1 seek $file, $startpos, 0; read $file, my $calender_date, 31; #if date is 8 chars change to 30 print $calender_date; }
This simply just pattern matches then seeks from the match.use File::Slurp; my $file = read_file( "1.rtf" ); $match0 = "Date of Last Update: "; $match1 = "Sign-Off Approvals"; $match2 = "Jane Doe, CEO"; if ($file =~ /$match0/){ open my $file, "<", "1.rtf"; my $startpos0 = "@-"; seek $file, $startpos0 +2, 0; read $file, my $calender_date, 29; if ($calender_date =~ /\\/){ seek $file, $startpos0 +2, 0; read $file, my $calender_date, 31; print "\n"; print "$calender_date\n\n"; } else { print "\n"; print "$calender_date\n\n"; } } if ($file =~ /$match1/){ open my $file, "<", "1.rtf"; my $startpos1 = "@+"; seek $file, $startpos1 +42, 0; read $file, my $first_sig, 66; print "$first_sig\n"; print "Jane Doe\n\n"; } if ($file =~ /$match2/){ open my $file, "<", "1.rtf"; my $startpos2 = "@+"; seek $file, $startpos2 +82, 0; read $file, my $second_sig, 67; print "$second_sig\n"; print "John Doe\n\n"; } prints: C:\Users\guy\Desktop\tests>test.pl Date of Last Update: 10/15/2013 ______________________________________________________/_____/_____ Jane Doe ______________________________________________________/_____/_____ John Doe
this also includes if your date is only 8 characters eg: 1/1/2013. if not, then dont worry about it.if (first_sig = "_____________________________________________________ +_/_____/_____"){ print "There is no first signature"; } else{ print "Document has a first signature"; } if (second_sig = "____________________________________________________ +__/_____/_____"){ print "There is no second signature\n"; } else{ print "Document has a second signature\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How can I find a line in a RTF file?
by kevyt (Scribe) on Aug 09, 2014 at 18:43 UTC | |
by james28909 (Deacon) on Aug 10, 2014 at 00:21 UTC | |
by james28909 (Deacon) on Aug 10, 2014 at 00:24 UTC | |
|
Re^2: How can I find a line in a RTF file?
by kevyt (Scribe) on Aug 09, 2014 at 08:25 UTC |