At 07:58 -0700 01/11/2010, Warren Michelsen wrote:

Within each file passed to the Perl script, I want to find the line beginning "movieYear : " and get the four digits following the space and before the line end character.


^movieYear : (\d{4})

I need to append a space and the four digits (within parentheses) to the end of the line beginning "title : "

So, if I call the Perl script:

/path/to/perl/script.pl /path/to/Phantom.txt /path/to/Kong.txt

and if the files passed to the script contain among their lines....

Phantom.txt
some text
More text
movieYear : 1925
additional lines of text
title : The Phantom of the Opera
more lines ...


Here's a way to do it using a UNIX filter on an open BBEdit document:

(Filename: "p.pl")

#!/usr/bin/perl
use strict;
my $year;
while (<>){
  m~^(movieY.+)([0-9][0-9][0-9][0-9])[ \t]?~i and $year = " ($2)";
  s~^(title.*)~$1$year~;
  print;
}


In the Terminal
perl p.pl a.txt
will print the result to STDOUT.




JD

--
You received this message because you are subscribed to the "BBEdit Talk" discussion group on Google Groups.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
<http://groups.google.com/group/bbedit?hl=en>
If you have a feature request or would like to report a problem, please email "[email protected]" rather than posting to the group.
Follow @bbedit on Twitter: <http://www.twitter.com/bbedit>

Reply via email to