On May 25, 2012, at 7:34 AM, thegermanguy wrote:

> Hi everyone
> 
> my boss just came down on me with a slavish task and I was hoping
> someone here had an easy (scripting?) solution for it. I've never
> written a line of code, so please forgive if my expectations are
> unrealistic.
> 
> I hava a huge file and need to change things repeatedly in the
> following manner:
> 
> The lines I need to change ALWAYS follow a line saying
> 
> <MTypeName `Index'> (so easy to find)
> 
> Then the line I need to change reads for example
> 
> <MText `N.: suprascapularis'>
> 
> and needs to be changed to
> 
> <MText `N. suprascapularis; Nervus suprascapularis'>
> 
> i.e.
> 
> - delete the colon after in this example the "N."
> - insert a semicolon before the " ' "
> - repeat the term
> - but replace the "N." with "Nervus" (or, if it's a "V." with "Vena"
> and there are about 8 different possibilities to be replaced with
> different words)
> 
> I Imagine for someone who knows what they are doing, this should be a
> ridiculously simple task, needing a few lines of code. For me, on
> foot, so to say, it'll probably take a week or so.
> 
> Could anybody help me out here?
> 
> All the best, thegermanguy

thegermanguy,

You can use this simple perl program to make your changes.

To use it, in Terminal do the following:
$ cat OLDFILE | perl slavish.pl > NEWFILE

This will make a copy of OLDFILE called NEWFILE with the changes you desire 
(while preserving the original).
This is a simple program, which could be optimized and have more error 
checking, yet it will do the job and 
is pretty straightforward to read.

You will need to modify it for your other conversion variations, this is marked 
and should be easy to follow.

Good Luck 

Matt

_______________________________________________________________________
#!/usr/bin/perl

$index_line = q[<MTypeName `Index'>];

while ( $line = <> ) {

    if ( $line =~ m|$index_line| ) {
        $change_line = <>;
        $change_line =~ s|<MText `N\.: (.*)'>|<MText `N. $1; Nervus $1'>|;
        $change_line =~ s|<MText `V\.: (.*)'>|<MText `V. $1; Vena $1'>|;

        ### Add in the other variations here, remove the # at the beginning of 
the line
    #   $change_line =~ s|<MText `X\.: (.*)'>|<MText `X. \1; XRAY \1'>|;
    #   $change_line =~ s|<MText `Y\.: (.*)'>|<MText `Y. \1; YANKEE \1'>|;
    #   $change_line =~ s|<MText `Z\.: (.*)'>|<MText `Z. \1; ZULU \1'>|;

        print $line;
        print $change_line;
    } else {
        print $line;
    }
}

_______________________________________________________________________

Test File:

I hava a huge file and need to change things repeatedly in the
following manner:
The lines I need to change ALWAYS follow a line saying
<MTypeName `Index'>
<MText `N.: suprascapularis'>
more stuff
<MTypeName `Index'>
<MText `V.: supraorbital'>
even more stuff
<MTypeName `Index'>
<MText `N.: supernaut'>
still more stuff

_______________________________________________________________________


-- 
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