🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.misc.discuss
Article #2151

Re: A very simple question on SED or AWK for a GURU, possibly a lisp script or emacs batch processing of many files

#2151
From: Christopher J. White
Date: Tue, 14 Jan 2003 03:46
42 lines
2364 bytes
Here's my quick perl solution...

Save as "junk.pl", then run as "junk.pl <file1> <file2> <file3> ... ". 
Each file is renamed to <file>.old, output <file>.  For each

Note, this assumes that there are no double quotes in the label
expression to be manipulated.  I can't see how you'd determine the
end of the expression if this isn't true (unless double quotes
might be quoted with a backslash or something).  

#!/usr/bin/perl

foreach my $outfile (@ARGV) 
{
    my $infile = $outfile . ".old";

    print "infile: $infile\n";
    print "outfile: $outfile\n";

    my $line, $s1, $s2, $s3;

    rename $outfile, $infile;

    open INFILE, "<$infile";
    open OUTFILE, ">$outfile";

    while ($line = <INFILE>) {
        if ($line =~ /^(.*)label=\"([^\"]*)\"(.*)$/)
        {
            $s1 = $1; $s2 = $2; $s3 = $3;
            $s2 =~ s/\//_/g;
            print OUTFILE $s1 . "label=\"" . $s2 . "\"" . $s3 . "\n";
        }
        else
        {
            print OUTFILE $line;
        }
    }

    close INFILE;
    close OUTFILE;
}
Technical Details
Message-ID: <m2vg0stmv8.fsf@bluesteel.grierwhite.com>
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!gestalt.direcpc.com!telocity-west!DIRECTV!sn-xit-03!sn-xit-01!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
References: <b00bb831.0301131603.34e9704c@posting.google.com>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: 1025b4,1e8c4b23af1e4636
X-Google-Attributes: gid1025b4,public
X-Google-Thread: f4fd2,1e8c4b23af1e4636
X-Google-Attributes: gidf4fd2,public
X-Google-Thread: 103b8b,1e8c4b23af1e4636
X-Google-Attributes: gid103b8b,public
X-Google-ArrivalTime: 2003-01-13 19:46:24 PST
Path: arc1-ca.pugleaf.net!archiver1.google.com!news1.google.com!newsfeed.stanford.edu!cyclone.bc.net!sjc70.webusenet.com!news.webusenet.com!gestalt.direcpc.com!telocity-west!DIRECTV!sn-xit-03!sn-xit-01!sn-post-02!sn-post-01!supernews.com!corp.supernews.com!not-for-mail
From: chris@grierwhite.com (Christopher J. White)
Newsgroups: gnu.misc.discuss,comp.lang.lisp,gnu.emacs.help
Subject: Re: A very simple question on SED or AWK for a GURU, possibly a
 lisp script or emacs batch processing of many files
Date: Mon, 13 Jan 2003 22:46:03 -0500
Organization: Posted via Supernews, http://www.supernews.com
Message-ID: <m2vg0stmv8.fsf@bluesteel.grierwhite.com>
References: <b00bb831.0301131603.34e9704c@posting.google.com>
User-Agent: Gnus/5.090007 (Oort Gnus v0.07) Emacs/21.2
 (powerpc-apple-darwin)
Cancel-Lock: sha1:+S5URORbr7wDVq52NdOQaYmxT8E=
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
X-Complaints-To: abuse@supernews.com
Lines: 43