paulonline
Technical User
Hi all,
I have a question regarding perl that I hope you can help with.
I am trying to create an array from a hosts file, while at the same time removing unwanted lines, also i want to store only 2 of the colums from the file into the array.
--- hosts file example ---
#start of hosts file
10.0.2.10 machine1 mdlocal service1 service2
10.0.2.11 machine2 mdlocal service1 service2
#middle of hosts file
10.0.2.12 machine3 mdlocal service1
10.0.2.13 machine4
#end of hosts file
If I use the following code (with awk script I get the following output)
@get_host_list = `/usr/bin/grep mdlocal hosts | grep -v \"#\" | /usr/bin/awk \'\{print \$2,\$1\}\' | /usr/bin/sort -u` ;
print @get_host_list ;
output :-
machine1 10.0.2.10
machine2 10.0.2.11
machine3 10.0.2.12
So using perl only how would I extract column 1 & 2 and put only those values into the array.
Cheers
Paul
I have a question regarding perl that I hope you can help with.
I am trying to create an array from a hosts file, while at the same time removing unwanted lines, also i want to store only 2 of the colums from the file into the array.
--- hosts file example ---
#start of hosts file
10.0.2.10 machine1 mdlocal service1 service2
10.0.2.11 machine2 mdlocal service1 service2
#middle of hosts file
10.0.2.12 machine3 mdlocal service1
10.0.2.13 machine4
#end of hosts file
If I use the following code (with awk script I get the following output)
@get_host_list = `/usr/bin/grep mdlocal hosts | grep -v \"#\" | /usr/bin/awk \'\{print \$2,\$1\}\' | /usr/bin/sort -u` ;
print @get_host_list ;
output :-
machine1 10.0.2.10
machine2 10.0.2.11
machine3 10.0.2.12
So using perl only how would I extract column 1 & 2 and put only those values into the array.
Cheers
Paul