Sponsored Content
Top Forums Shell Programming and Scripting Code help with search script perl Post 302316154 by richsark on Thursday 14th of May 2009 08:21:37 AM
Old 05-14-2009
Code help with search script perl

Hello,

I have a script, but its sorta broke and I need help to tweak it

Code:
#!/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

Last edited by richsark; 05-14-2009 at 09:44 AM.. Reason: clairifcation
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Perl code to search for filenames that contain special characters

Hello, I have a requirement to search a directory, which contains any number of other directories for file names that contain special characters. directory structure DIR__ |__>DIR1 |__>DIR2__ |__>DIR2.1 |__>DIR2.2 |__>DIR3 .. ... (8 Replies)
Discussion started by: jerardfjay
8 Replies

2. Shell Programming and Scripting

Help with perl script to search webpage

i have to point out that i'm a avid shell script lover and i have next to zero interest in perl which is why i dont know the first thing about it. however, just need to do this one thing on it.. i need to do something in perl but dont know how. I have a list of email addresses in the following... (5 Replies)
Discussion started by: Terrible
5 Replies

3. Shell Programming and Scripting

search & replace password perl script

I wanted a perl script to be done for Password search & replace in two files. For Example: Example 1)--i am having a file such as cat /opt/customer/Ariba/UAT/ariba/app/buyer/Server/config/Parameters.table Example 2)--and i am having a other file in other location such as cat... (4 Replies)
Discussion started by: shellscript22
4 Replies

4. UNIX for Dummies Questions & Answers

Perl search and replace not working in csh script

I am using perl to perform a search and replace. It works at the command line, but not in the csh shell script perl -pi -e 's@/Pattern@@g' $path/$file I used the @ as my delimiter because the pattern contains "/" (3 Replies)
Discussion started by: NobluesFDT
3 Replies

5. Shell Programming and Scripting

Perl script to search sprintf and replace with snprintf

Dear all, I am new to perl script and would need some help for my 1st script. I wrote a script to search sprintf(buf,"%s", sourcestring) and replace with snprintf(buf, sizeof(buf),"%s", sourcestring). As snprintf() requires an extra argument, so it is not a simple search-and-replace. I need to... (1 Reply)
Discussion started by: ChaMeN
1 Replies

6. Shell Programming and Scripting

Perl script to search and extract using wildcards.

Good evening All, I have a perl script to pull out all occurrences of a files beginning with xx and ending in .p. I will then loop through all 1K files in a directory. I can grep for xx*.p files but it gives me the entire line. I wish to output to a single colum with only the hits found. ... (3 Replies)
Discussion started by: CammyD
3 Replies

7. Shell Programming and Scripting

perl script to search n place a pattern

hi, i have one file as t1.txt as below hi hello welcome i want perl script to search for the pattern "abcd" in the file. if the pattern doesn't exist, i want to insert that pattern at the end of the same file t1.txt my o/p should be hi hllo welcome abcd thank you (3 Replies)
Discussion started by: roopa
3 Replies

8. UNIX and Linux Applications

Perl Script to read an excel file into an array and search in the UNIX directories

Hi, I want the Perl script with versions 5.8.2 and 5.8.5 starting with #!/usr/bin/perl The Perl program should read the excel file or text file line by line and taking into an array and search in the UNIX directories for reference file of .jsp or .js or .xsl with path .The Object names... (2 Replies)
Discussion started by: pasam
2 Replies

9. Shell Programming and Scripting

perl code to search existing files

Hi, I have a string like: read_lib {$lib/a.lib $lib/b.lib $lib/c.lib ..... } Now, I want to search existence of all these *.lib files in $lib directory. Please suggest- how to do it. Thanks -rkg (2 Replies)
Discussion started by: rkg
2 Replies

10. UNIX for Beginners Questions & Answers

Using forward slash in search pattern in perl script

I have existing pattern in the perl script as: my $pattern = "^Line.*?:|^Errors*: |^SEVERE:.*?:|^Null pointer exception occurred"; and I wanted to include below keywords in my search pattern "I/O exception" and "FileNotFoundException"the problem is when I include my pattern like my... (5 Replies)
Discussion started by: ambarginni
5 Replies
WWW::RobotRules(3)					User Contributed Perl Documentation					WWW::RobotRules(3)

NAME
WWW::RobotsRules - Parse robots.txt files SYNOPSIS
require WWW::RobotRules; my $robotsrules = new WWW::RobotRules 'MOMspider/1.0'; use LWP::Simple qw(get); $url = "http://some.place/robots.txt"; my $robots_txt = get $url; $robotsrules->parse($url, $robots_txt); $url = "http://some.other.place/robots.txt"; my $robots_txt = get $url; $robotsrules->parse($url, $robots_txt); # Now we are able to check if a URL is valid for those servers that # we have obtained and parsed "robots.txt" files for. if($robotsrules->allowed($url)) { $c = get $url; ... } DESCRIPTION
This module parses a /robots.txt file as specified in "A Standard for Robot Exclusion", described in <http://info.webcrawler.com/mak/projects/robots/norobots.html> Webmasters can use the /robots.txt file to disallow conforming robots access to parts of their web site. The parsed file is kept in the WWW::RobotRules object, and this object provides methods to check if access to a given URL is prohibited. The same WWW::RobotRules object can parse multiple /robots.txt files. The following methods are provided: $rules = WWW::RobotRules->new($robot_name) This is the constructor for WWW::RobotRules objects. The first argument given to new() is the name of the robot. $rules->parse($robot_txt_url, $content, $fresh_until) The parse() method takes as arguments the URL that was used to retrieve the /robots.txt file, and the contents of the file. $rules->allowed($uri) Returns TRUE if this robot is allowed to retrieve this URL. $rules->agent([$name]) Get/set the agent name. NOTE: Changing the agent name will clear the robots.txt rules and expire times out of the cache. ROBOTS.TXT The format and semantics of the "/robots.txt" file are as follows (this is an edited abstract of <http://info.webcrawler.com/mak/projects/robots/norobots.html>): The file consists of one or more records separated by one or more blank lines. Each record contains lines of the form <field-name>: <value> The field name is case insensitive. Text after the '#' character on a line is ignored during parsing. This is used for comments. The following <field-names> can be used: User-Agent The value of this field is the name of the robot the record is describing access policy for. If more than one User-Agent field is present the record describes an identical access policy for more than one robot. At least one field needs to be present per record. If the value is '*', the record describes the default access policy for any robot that has not not matched any of the other records. Disallow The value of this field specifies a partial URL that is not to be visited. This can be a full path, or a partial path; any URL that starts with this value will not be retrieved ROBOTS.TXT EXAMPLES The following example "/robots.txt" file specifies that no robots should visit any URL starting with "/cyberworld/map/" or "/tmp/": User-agent: * Disallow: /cyberworld/map/ # This is an infinite virtual URL space Disallow: /tmp/ # these will soon disappear This example "/robots.txt" file specifies that no robots should visit any URL starting with "/cyberworld/map/", except the robot called "cybermapper": User-agent: * Disallow: /cyberworld/map/ # This is an infinite virtual URL space # Cybermapper knows where to go. User-agent: cybermapper Disallow: This example indicates that no robots should visit this site further: # go away User-agent: * Disallow: / SEE ALSO
LWP::RobotUA, WWW::RobotRules::AnyDBM_File libwww-perl-5.65 2001-04-20 WWW::RobotRules(3)
All times are GMT -4. The time now is 09:20 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy