Nick Ellson wrote:

> I have a search and replace task and was hoping to get some advice. I
> have a large text file of remote access users from Cisco's ACS
> dumpfile that I need to batch alter 2000 of 3000 users. And example
> user record (they are not all the same size)

they are not all the same size means the number of rows for each record 
might be different or that each line can have variable length or both? 
depending on those, your solution can be much simpler.

> 
#---------------------------------------------------------------------------
> --
> Name          :       myuser
> State         :       0
> S_flags       :       0
> Aging policy  :       group1
> Good count    :       0
> Warning count :       0
> Change count  :       0
> Last change Lo:       1648245808
> Last change Hi:       29591352
> Last auth Lo  :       0
> Last auth Hi  :       0
> Rights        :       1
> Type          :       256
> EnableType    :       4
> Status        :       4
> Reset         :       1
> Expiry        :       302     103     0       4294963983      0       5
> MaxSession    :       65535
> MaxSess2      :       0
> Profile       :       1
> LogonHrs      :       0x0016 00 ff ff ff ff ff ff ff ff ff ff ff ff ff ff ff
> ff ff ff ff ff ff
> Alias         :       0
> Value Flags   :       524336
> CounterVals_00:       0       0       0       0
> CounterRst_00 :       0       0
> CounterVals_01:       0       0       0       0
> CounterRst_01 :       0       0
> ##--- User End
> 

you didn't mention how each record is separated from the other records. 

[snip]

> So I am betting Perl is my best and perhaps only
> option to do this with minimal developement time. Any text
> manipulators out there see a way to do this from what I have
> described?

maybe, we will see. :-) see if the following works for you:

#!/usr/bin/perl -w
use strict;

my $user;

while(<>){
        chomp;
        if(/^Name\s+:\s+(\S+)/){
                $user = $1;
                print "$_\n";
        }else{
                if(/^(Type\s+:\s+)\S+/ && defined $user){
                        #--
                        #-- look up Type for $user. i am
                        #-- giving it a type of -1 here for demo
                        #--
                        print $1,"-1\n";
                }elsif(/^(Status\s+:\s+)\S+/ && defined $user){
                        #--
                        #-- look up Status for $user. i am
                        #-- giving it a status of -2 here for demo
                        #--
                        print $1,"-2\n";
                        $user = undef;
                }else{
                        print "$_\n";
                }
        }
}

__END__

like i said, depends on how your records are stored, your solution can be 
much simpler. for example, if each record is separated by '--' on its own, 
you might be able to set $/ to '--' and just read each record as they come 
along. Or if all records have the same number of rows, you can read a fixed 
number of lines for each record and do something with them. what i suggest 
do not make any of those assumption.

david
-- 
s,.*,<<,e,y,\n,,d,y,.s,10,,s
.ss.s.s...s.s....ss.....s.ss
s.sssss.sssss...s...s..s....
...s.ss..s.sss..ss.s....ss.s
s.sssss.s.ssss..ss.s....ss.s
..s..sss.sssss.ss.sss..ssss.
..sss....s.s....ss.s....ss.s

,....{4},"|?{*=}_'y!'+0!$&;"
,ge,y,!#:$_(-*[./<[EMAIL PROTECTED],b-t,
.y...,$~=q~=?,;^_#+?{~,,$~=~
y.!-&*-/:[EMAIL PROTECTED] ().;s,;,
);,g,s,s,$~s,g,y,y,%,,g,eval

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to