parse a file

Hi,

we have a tool and when we run it, its output is like the following.  Now what I need to get is the list of all the strings just before the word [Group]. So the output of parsing the following file should be like this. And the output can be variable I mean it should go through the entire file and look for the string [Group]. Hope I am clear enough

MI_AP_L2_NRRT
MI_AP_L2_RRT
MI_AP_NL2_NRRT
MI_EU_CapacityPlanning

-------------------------------------------------------------------------------------------------
2/4/2008 9:37:55 AM   Version: 8.1.0 (Build 8.1.000.149)
2/4/2008 9:37:55 AM   Project Source: 1-DEV (SMFIMDMSI01)
2/4/2008 9:37:55 AM   Login: administrator
2/4/2008 9:37:55 AM   Executing task(s)...
2/4/2008 9:37:55 AM   Members = MI_AP_L2_NRRT [Group], MI_AP_L2_RRT [Group], MI_AP_NL2_NRRT [Group], MI_AP_NL2_RRT [Group]
2/4/2008 9:37:55 AM   Members = MI_EU_CapacityPlanning [Group], MI_EU_L2_NRRT [Group], MI_EU_L2_RRT [Group], MI_EU_NL2_NRRT [Group]
2/4/2008 9:37:55 AM   Members = MI_EU_NL2_RRT [Group], MI_NA_BIDeveloper [Group], MI_NA_L2_NRRT [Group], MI_NA_L2_RRT [Group]
2/4/2008 9:37:55 AM   Members = MI_NA_NL2_NRRT [Group], MI_NA_NL2_RRT [Group], MI_Others [Group], MI_OthersL2 [Group]
2/4/2008 9:37:55 AM   Task(s) execution completed successfully.
anshumaEngineeringAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Adam314Commented:
Use like:
    program.pl output.txt
where program.pl is the perl program (below), and output.txt is the output from your tool
my %Found;
while(<>) {
	while(/([\w_]+)\s*\[Group\]/g) {
		next if $Found{$1};
		$Found{$1}=1;
		print "$1\n";
	}
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
ozoCommented:
perl -lne '$found{$_}++ or print for /(\w+)\s+\[Group\]/g'
or in mswindows
perl -lne "$found{$_}++ or print for /(\w+)\s+\[Group\]/g"

0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Perl

From novice to tech pro — start learning today.