
richsark
User
May 14, 2009, 6:01 AM
Post #1 of 16
(808 views)
|
|
Code help with search script
|
Can't Post
|
|
I have a script, but its sorta broke and I need help to tweak it.
#!/usr/bin/perl my @files_to_search = ("exportOBJ-sark.txt","ResourceRecText-ALL.txt","exportdnsrr-report.txt"); open (FL, "sark.com.txt"); my %search_hash = (); while (my $line = <FL>) { my @parts = split(/,/,$line); $search_hash{$parts[0]} = 1; $search_hash{$parts[4]} = 1; } close(FL); foreach my $file (@files_to_search) { open (FL, $file); while (my $line = <FL>) { foreach my $key (keys %search_hash) { if ($line =~ /$key/) { print $line; } } } close(FL); } The above script takes input file named sark.com.txt which contains this type of info: ao,300,IN,CNAME,www.sark.com.,,, bd-integ4-sarkprime,IN,NS,gss-t2i.is.sark.com.,,,, sarkhub,IN,MX,5,sarkhub1,,, bpm,IN,NS,gss-t2p.is.sark.com.,,,, bpmqa,IN,NS,gss-t2i.is.sark.com.,,,, from the above example we take one record (bd-integ4-sarkprime,IN,NS,gss-t2i.is.sark.com.,,,,) ( for example) strip it and it should result as: bd-integ4-sarkprime and gss-t2i.is.sark.com The script should then look for bd-integ4-sarkprime and gss-t2i.is.sark.com in the 3 files (exportOBJ-sark.txt","ResourceRecText-ALL.txt","exportdnsrr-report.txt) (BTW..The format above will not change.) Then I want it to search inside 3 files for any matches to bd-integ4-sarkprime and gss-t2i.is.sark.com to report on it. called exportOBJ-sark.txt (example of contents) 10.0.234.254,cli2821cncx-stmin-00-01,,,is.sark.com,Server,"",,,,,-1,0,,,-1,,3,, 10.0.237.254,cli2821cncx-tgsp-00-01,,,is.sark.com,Server,"",,,,,-1,0,,,-1,,3,, For "exportOBJ-sark.txt" I can remove the ",,," manually before running the script so it can join as cli2821cncx-stmin-00-01.is.sark.com, or if the script can do that? ResourceRecText-ALL.txt (example of contents) outputRR-sark.com.txt:ResourceRecText=whdgss1infz-qapri1.is.sark.com. outputRR-sark.com.txt:ResourceRecText=n3mgss1infz-qasec1.is.sark.com. exportdnsrr-report.txt (example of contents) srsservicing.net,sarkprivate.srsservicing.net,IN,A,-1,100.168.67.190,,,0,0,"","" srsservicing.net,sarkmanagedcontrolprivate.srsservicing.net,IN,A,-1,100.168.67.189,,,0,0,"","" Can I get some help to tune this up please. Thanks
|