Link to home
Start Free TrialLog in
Avatar of dpk_wal
dpk_walFlag for India

asked on

extract data from text file

I have a 30,000 file text file from which I need to extract data; I will start with example.

Let's say I have three network object-group in the file as A,B and C with different objects as below:

object-group network C
 network-object host 10.57.31.66
 network-object host 10.57.31.67
 network-object host 10.80.40.201
 network-object host 10.80.40.202
object-group network A
 network-object 10.14.60.0 255.255.252.0
 network-object 10.14.63.0 255.255.255.0
 network-object 10.14.64.0 255.255.255.0
object-group network B
 network-object host 10.13.5.116
 network-object host 10.13.5.117


I need to extract group A and C from the file along with all other lines; i.e. line with object A and next 3 lines and then object C and next 4 lines.

Please help.
ASKER CERTIFIED SOLUTION
Avatar of wilcoxon
wilcoxon
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpk_wal

ASKER

Thank you for quick post; in above can we also read A and B from a text file.
The file would have entries like:
A
B
.
.
.
Z

Regards.
Avatar of dpk_wal

ASKER

Sorry for my limited knowledge with scripting, here is what I have done:
-rwxrwxrwx  1 root root 525 Feb 18 12:14 a
-rwxrwxrwx  1 root root 393 Feb 18 12:12 txtFile

Changed code above as:
#!/usr/bin/perl
open IN, $txtFile or die "could not open $txtFile: $!";

Getting error as below:
[root@myhost]# ./a
Global symbol "$txtFile" requires explicit package name at ./a line 10.
Global symbol "$txtFile" requires explicit package name at ./a line 10.
Execution of ./a aborted due to compilation errors.

Thank you for all your help.
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of dpk_wal

ASKER

Thank you for all the help.
Avatar of dpk_wal

ASKER

Thank you!