Search pattern not terminated


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Search pattern not terminated
# 1  
Old 04-24-2009
Search pattern not terminated

Hi,

What am i missing on line 16, when I run this I get
Search pattern not terminated at count-scr.pl line 16

Code:
#!perl open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n"; ##### Step 1, read subnetsopen(my $in, "<names.txt") or die "Could not open names.txt: $!\n";while(<$in>) {    next unless /(.*?)\/(.*)$/;    my $subnet = $1;    print "Checking $subnet\n";    my @dnsoptions = `./object.exe -u Xxx-p Xxx -b $subnet -o rich`;        my %counts;    foreach my $line (@dnsoptions) {        my @f = split/"\s+", $line;        $counts{$f[3]}++;    }        print $log "For subnet $subnet:\n";    foreach my $k (keys %counts) {        print $log "    $k: $counts{$k}\n";    }} close($log);

Thanks
# 2  
Old 04-24-2009
fixed format:

Any idea on what I am missing? regarding the error I get

Search pattern not terminated Line 16

Code:
#!perl
 
open(my $log, ">log-subnet.txt") or die "Could not open log: $!\n";
 
##### Step 1, read subnets
open(my $in, "<names.txt") or die "Could not open names.txt: $!\n";
while(<$in>) {
   next unless /(.*?)\/(.*)$/;
   my $subnet = $1;
   print "Checking $subnet\n";
   my @dnsoptions = `./object.exe -u Xxx-p Xxx -b $subnet -o rich`;
 
   my %counts;
   foreach my $line (@dnsoptions) {
       my @f = split/"\s+", $line;
       $counts{$f[3]}++;
   }
 
   print $log "For subnet $subnet:\n";
   foreach my $k (keys %counts) {
       print $log "    $k: $counts{$k}\n";
   }
}
 
close($log);

# 3  
Old 04-24-2009
Quote:
Originally Posted by richsark
fixed format:

Any idea on what I am missing? regarding the error I get

Search pattern not terminated Line 16

Code:
...
...
   foreach my $line (@dnsoptions) {
       my @f = split/"\s+", $line;
       $counts{$f[3]}++;
   }
... 
...

The syntax of the split command is:

Code:
1.  split /PATTERN/,EXPR,LIMIT 
2.  split /PATTERN/,EXPR 
3.  split /PATTERN/ 
4.  split

(It splits the string EXPR, considering PATTERN as the delimiter, with LIMIT being the max. number of fields EXPR is split into.)

So, the line no. 15 of your script should be changed thusly:

Code:
       my @f = split/"\s+"/, $line;

or

Code:
       my @f = split/\s+/, $line;

Hope that helps,
tyler_durden
# 4  
Old 04-25-2009
Yup, thanks !
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Grep/awk using a begin search pattern and end search pattern

I have this fileA TEST FILE ABC this file contains ABC; TEST FILE DGHT this file contains DGHT; TEST FILE 123 this file contains ABC, this file contains DEF, this file contains XYZ, this file contains KLM ; I want to have a fileZ that has only (begin search pattern for will be... (2 Replies)
Discussion started by: vbabz
2 Replies

2. Shell Programming and Scripting

A shell script to run a script which don't get terminated and send a pattern from the output by mail

Hi Guys, I am very new to shell script and I need your help here to write a script. Actually, I have a script abc.sh which don't get terminated itself. So I need to design a script to run this script, save the output to a file, search for a given string in the output and if it exists send those... (11 Replies)
Discussion started by: Sambit Sahu
11 Replies

3. Shell Programming and Scripting

Search pattern on logfile and search for day/dates and skip duplicate lines if any

Hi, I've written a script to search for an Oracle ORA- error on a log file, print that line and the .trc file associated with it as well as the dateline of when I assumed the error occured. In most it is the first dateline previous to the error. Unfortunately, this is not a fool proof script.... (2 Replies)
Discussion started by: newbie_01
2 Replies

4. Shell Programming and Scripting

How to use sed to search a particular pattern in a file backward after a pattern is matched.?

Hi, I have two files file1.txt and file2.txt. Please see the attachments. In file2.txt (which actually is a diff output between two versions of file1.txt.), I extract the pattern corresponding to 1172c1172. Now ,In file1.txt I have to search for this pattern 1172c1172 and if found, I have to... (9 Replies)
Discussion started by: saurabh kumar
9 Replies

5. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

6. Shell Programming and Scripting

Awk to match a pattern and perform a search after the first pattern

Hello Guyz I have been following this forum for a while and the solutions provided are super useful. I currently have a scenario where i need to search for a pattern and start searching by keeping the first pattern as a baseline ABC DEF LMN EFG HIJ LMN OPQ In the above text i need to... (8 Replies)
Discussion started by: RickCharles
8 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. Shell Programming and Scripting

Print a pattern between the xml tags based on a search pattern

Hi all, I am trying to extract the values ( text between the xml tags) based on the Order Number. here is the sample input <?xml version="1.0" encoding="UTF-8"?> <NJCustomer> <Header> <MessageIdentifier>Y504173382</MessageIdentifier> ... (13 Replies)
Discussion started by: oky
13 Replies

9. Shell Programming and Scripting

perl:: search for tow pattern and replace the third pattern

Hi i want to search two pattern on same line and replace onther pattern.. INPut file aaaa bbbbb nnnnnn ttttt cccc bbbbb nnnnnn ppppp dddd ccccc nnnnnn ttttt ffff bbbbb oooooo ttttt now i want replace this matrix like.. i want search for "bbbbb","nnnnnn" and search and replace for... (4 Replies)
Discussion started by: nitindreamz
4 Replies

10. Shell Programming and Scripting

search a pattern and if pattern found insert new pattern at the begining

I am trying to do some thing like this .. In a file , if pattern found insert new pattern at the begining of the line containing the pattern. example: in a file I have this. gtrow0unit1/gctunit_crrownorth_stage5_outnet_feedthru_pin if i find feedthru_pin want to insert !! at the... (7 Replies)
Discussion started by: pitagi
7 Replies
Login or Register to Ask a Question