dpk_wal
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.
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.
-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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you for all the help.
ASKER
Thank you!
ASKER
The file would have entries like:
A
B
.
.
.
Z
Regards.