[Webinar] Streamline your web hosting managementRegister Today

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 198
  • Last Modified:

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.
0
anshuma
Asked:
anshuma
2 Solutions
 
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
 
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

Featured Post

Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Tackle projects and never again get stuck behind a technical roadblock.
Join Now