Hi Dave That did what I wanted and very well too :-) I had got all of file into array and was hacking away when this came to me so - thanks a lot. I'll put in the solution with arrays also , just for record. The solution using the config inifile module is also pretty elegant and custom made for this kind of situation but it doesn't come out as a standard distribution with active perl ( as far as I could make out) and since this is a partof tool that gets distributed , the users would have to make sure that the module is in place. Regards Sundar
-----Original Message----- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 06, 2002 3:01 PM To: [EMAIL PROTECTED] Subject: RE: [Perl-unix-users] Multiple Pattern Match If I understand you correctly...Here is a script I threw together... I just cut and pasted your file contents into a file named "dave.dat" ran the following script and it did what I think you wanted to accomplish...I also moved the [jwg] section around in the file and it still worked... Hope this helps... #!/usr/bin/perl open(INFILE, "dave.dat") || die; my $flag=0; my $newpass="hello"; while ( <INFILE> ) { # Reset the flag each time it finds a new section. $flag=0 if ( /^[\[]/ ); # Flip the flag if we reach the desired section. $flag=1 if ( /^\[jwg\]/ ); # Change the record if we are in the desired section and on the correct line. $_="password = $newpass\n" if ( $flag && /^password/ ); print "$_"; } close(INFILE); Regards, Dave. -----Original Message----- From: surajan [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 06, 2002 7:38 AM To: perl-win32-users; perl-unix-users Subject: [Perl-unix-users] Multiple Pattern Match Hi all I'm trying to parse a text file match a pattern and if it does pick up the line after and make changes to it if a file has matter such as [abc] username = sssh password = ghsgas [def] username = ghshgs password = hsjhsa [jwg] username = shjsjhsa password = jhsjhs I need to , say substitute the password of section [jwg]. i can't use the nth instance substitute as the instances may change Thanks _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs _______________________________________________ Perl-Unix-Users mailing list [EMAIL PROTECTED] To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs