Re: Massive Search and Replace with a twist

Discussion in 'Perl' started by Craig R. Dunn, Aug 22, 2003.

  1. [snip]
    > -20 A1
    > -21 FLANGE BLIND
    > -1 150# RF A105
    > -20 A2
    >
    > I have been searching the internet for a possible solution and one
    > involves using "regular expressions" but this is the first time I have
    > ever heard this phrase. I do not know if it will help. All I really
    > need to do is to find a particular line (it always starts with "-20")
    > and then add an incremental number to whatever letter is there. I am
    > urgently seeking anyway to avoid manually opening up 1100 records and
    > editing them by hand.
    >



    Something like (there are probably shorter ways, but this should work):

    ### Create an array of all the files you want to
    ### modify, either manually or using readdir() or `ls`
    ### lets assume its @files

    for (@files) {
    $fname = $_;
    my $count=1;
    open (INFILE, $fname);
    open (OUTFILE, ">$fname.new");
    while (<INFILE>) {
    if (m/^\-20 A.*/) {
    s/A/A$count/;
    $count++;
    print OUTFILE $_;
    } else {
    print OUTFILE $_;
    }
    }
    }
    Craig R. Dunn, Aug 22, 2003
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mr Gordonz
    Replies:
    3
    Views:
    395
    Hans Kesting
    Aug 7, 2003
  2. =?Utf-8?B?VHJveQ==?=

    Image viewer with a twist

    =?Utf-8?B?VHJveQ==?=, Feb 28, 2005, in forum: ASP .Net
    Replies:
    4
    Views:
    554
    Brian Lowe
    Mar 2, 2005
  3. Jan Bakuwel
    Replies:
    1
    Views:
    364
    Bjoern Schliessmann
    Oct 11, 2006
  4. Jean-Paul Calderone
    Replies:
    2
    Views:
    277
    Jan Bakuwel
    Oct 13, 2006
  5. Evan
    Replies:
    3
    Views:
    101
Loading...

Share This Page