Code help with search script perl


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Code help with search script perl
# 8  
Old 05-18-2009
HI,

I saw your one example on
exportdnsrr-report.txt how about the other files/formats?

Thanks !
# 9  
Old 05-18-2009
Quote:
Originally Posted by richsark
...
I saw your one example on
exportdnsrr-report.txt how about the other files/formats?...
Depends on the delimiter and what exactly you want to match. The code assumes that:

(1) Your delimiter is a comma, and
(2) You want to match an entire token between delimiters i.e. this -

Code:
123,XYZ,abc,0.234

is a valid match for "abc", but this -

Code:
123,XYZ,param=abc,0.234

is not.

Since the delimiters for "exportOBJ-sark.txt" and "exportdnsrr-report.txt" are the same (comma), the code should work for both, assuming you want the match semantics like (2) above.

For the 3rd file - "ResourceRecText-ALL.txt", you'll have to split it as per the delimiter. And the rest of the logic remains the same.

tyler_durden
# 10  
Old 05-18-2009
Hi Durden,

Thanks for your reply. Would it be possiable to provide me a code for the last one?

"For the 3rd file - "ResourceRecText-ALL.txt", you'll have to split it as per the delimiter. And the rest of the logic remains the same"

I hate to be a burden, but I do not have the fore knowledge.

Also, I asumme I have to run this on the command line, and I get convert it to a script right?

Thanks !
# 11  
Old 05-18-2009
Quote:
Originally Posted by richsark
...Would it be possiable to provide me a code for the last one?

"For the 3rd file - "ResourceRecText-ALL.txt", you'll have to split it as per the delimiter. And the rest of the logic remains the same"
What's the delimiter in the 3rd file - "ResourceRecText-ALL.txt" ?

Quote:
...Also, I asumme I have to run this on the command line, and I get convert it to a script right?...
You can run it on the command line passing one file at a time.
Or you can incorporate the logic in a perl program that processes all your files.

tyler_durden
# 12  
Old 05-18-2009
Hi !

for 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.

I am looking to search only on what the name is after the =

so for the abve excerpt would be:
whdgss1infz-qapri1.is.sark.com.

and

n3mgss1infz-qasec1.is.sark.com.

Thanks

Does that help ?
# 13  
Old 05-19-2009
HI, I ran your slightly modified code, and I got the same response.

When I run it on my actual files, I dont get the same..

Code:
$ perl -ne 'BEGIN{open(F,sark.com.txt"); while(<F>) {chomp; split/,/; $s{$_[0]}=1; $s{$_[3]}=1}}

> {chomp; @x=split/,/; foreach $i(@x){if (defined $s{$i}) {print $_,"\n"; last} }}'exportOBJ-sark.txt


String found where operator expected at -e line 2, near "{chomp; @x=split/,/; foreach $i(@x){if (defined $s{$i}) {print $_,""
(Might be a runaway multi-line "" string starting on line 1)
(Missing semicolon on previous line?)
String found where operator expected at -e line 2, at end of line
(Missing semicolon on previous line?)
syntax error at -e line 2, near "{chomp; @x=split/,/; foreach $i(@x){if (defined $s{$i}) {print $_,""
Can't find string terminator '"' anywhere before EOF at -e line 2.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

5. 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

6. 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

7. 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

8. 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

9. 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

10. 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
Login or Register to Ask a Question