Sponsored Content
Top Forums Shell Programming and Scripting Find the occurence of particular string in log file Post 302745347 by maddyrox on Monday 17th of December 2012 06:55:09 AM
Old 12-17-2012
Actually, I have no idea how to write the script. This is actually my first time.
I wrote the code like this:
Code:
#!/usr/local/bin/perl

MAIN:
{

        while(<>)
        {
                $counts{$1} = 0 if (/\[(\d{4}-\d{2}-\d{2})/ ) && (! defined $cou
nts{$1})
                $counts{$1}++ if /\[(\d{4}-\d{2}-\d{2}).+STATUS/;
        }

        for $date (sort keys %counts)
        {
                print "$date , $counts{$date}\n";
        }
}

On running the code, I am getting following error:
Code:
bash-3.00$ perl test.pl license.log > status.log
Scalar found where operator expected at test.pl line 9, near ")
                $counts"
        (Missing operator before $counts?)
syntax error at test.pl line 9, near ")
                $counts"
syntax error at test.pl line 9, near "++ if"
syntax error at test.pl line 16, near "}"
Execution of test.pl aborted due to compilation errors.

Can you help me in this?

Last edited by Franklin52; 12-17-2012 at 10:46 AM.. Reason: Code tags
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Replace string B depending on occurence of string A

Depending upon the occurence of string 'xyz', I want to remove -t from the input file. There is not a fixed length input file. Any suggestions Input file: this is xyz line -t of the data this is line 2 of -t of the data xyz this is line 3 of -t the file this is line xyz of the -t file... (1 Reply)
Discussion started by: hemangjani
1 Replies

2. Shell Programming and Scripting

How to find vowel's occurence in a string

Hi All, I want to search the string for vowel's occurence and find the no of occurence of each vowels, Could anyone help me out? This is urgent to me...I m new to Shell programming.. Thanks and Regards, Nids:b: (4 Replies)
Discussion started by: Nidhi2177
4 Replies

3. Shell Programming and Scripting

Find index of last occurence of a character within a string

I need to find the index of last '|' (highlighted in bold) in awk : |ifOraDatabase.Lastservererr<>0then|iferr_flag<>0then|end if Please suggest a way... Thanks (5 Replies)
Discussion started by: joyan321
5 Replies

4. Shell Programming and Scripting

shell script to find the second occurence of the alphabet in a string

this is my assignment question. i'm supposed to submit it tommorow. can somebody please help me with it? Do not post homework questions in the main forums. Please post in the homework forum using the correct template. (0 Replies)
Discussion started by: vijjy
0 Replies

5. UNIX for Dummies Questions & Answers

To find the Nth Occurence of Search String

Hi guys, I like to find the Line number of Nth Occurence of a Search string in a file. If possible, if it will land the cursor to that particualar line will be great. Cheers!! (3 Replies)
Discussion started by: mac4rfree
3 Replies

6. Shell Programming and Scripting

Split a fixed length file bases on last occurence of string

Hi, I need to split a file based on last occurece of a string. PFB the explanation I have a file in following format aaaaaaaaaaaaaaaaaaaaaaaaaaa bbbbbbbbbbbbbbbbbbbbbbbbbbb ccccccccccccccccccccccccccc ddddddddddddddddddddddddddd 3186rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr... (4 Replies)
Discussion started by: Neelkanth
4 Replies

7. Shell Programming and Scripting

How to find the number of occurence of particular word from a text file?

example: i have the following text file... i am very tired. i am busy i am hungry i have to find the number of occurence of a particular word 'am' from the text file.. can any one give the shell script for it (34 Replies)
Discussion started by: sheela
34 Replies

8. Shell Programming and Scripting

Find and increment at each occurence of string (loop)

I created script (sh shell) to generate vlc playlist based on some data files. All works fine so far except one string I do not know how to handle with. VLCSTART='<vlc:id>' VLCV=0 VLCEND='</vlc:id>' echo -e $'\n'$'\t'$'\t'$'\t'$'\t'\$VLCSTART$VLCV$VLCENDOutput file contains several occurences... (10 Replies)
Discussion started by: TiedCone
10 Replies

9. Shell Programming and Scripting

Get nth occurence of string from a file

I have file in which the data looks like this, 01,0000000,xxxxxxx/ 02,xxxxxxxx,yyyyyy/ 03,test1,41203016,,/ 01,0000000,xxxxxxx/ 02,xxxxxxxx,yyyyyy/ ... (16 Replies)
Discussion started by: r@v!7*7@
16 Replies

10. Shell Programming and Scripting

Find string in file and find the all records by string

Hello I would like to get know how to do this: I got a big file (about 1GB) and I need to find a string (for instance by grep ) and then find all records in this file based on a string. Thanks for advice. Martin (12 Replies)
Discussion started by: mape
12 Replies
Test::SubCalls(3)					User Contributed Perl Documentation					 Test::SubCalls(3)

NAME
Test::SubCalls - Track the number of times subs are called SYNOPSIS
use Test::SubCalls; # Start tracking calls to a named sub sub_track( 'Foo::foo' ); # Run some test code ... # Test that some sub deep in the codebase was called # a specific number of times. sub_calls( 'Foo::foo', 5 ); sub_calls( 'Foo::foo', 5, 'Use a custom test message' ); # Reset the counts for one or all subs sub_reset( 'Foo::foo' ); sub_reset_all(); DESCRIPTION
There are a number of different situations (like testing caching code) where you want to want to do a number of tests, and then verify that some underlying subroutine deep within the code was called a specific number of times. This module provides a number of functions for doing testing in this way in association with your normal Test::More (or similar) test scripts. FUNCTIONS
In the nature of test modules, all functions are exported by default. sub_track $subname The "sub_track" function creates a new call tracker for a named function. The sub to track must be provided by name, references to the function itself are insufficient. Returns true if added, or dies on error. sub_calls $subname, $expected_calls [, $message ] The "sub_calls" function is the primary (and only) testing function provided by "Test::SubCalls". A single call will represent one test in your plan. It takes the subroutine name as originally provided to "sub_track", the expected number of times the subroutine should have been called, and an optional test message. If no message is provided, a default message will be provided for you. Test is ok if the number of times the sub has been called matches the expected number, or not ok if not. sub_reset $subname To prevent repeat users from having to take before and after counts when they start testing from after zero, the "sub_reset" function has been provided to reset a sub call counter to zero. Returns true or dies if the sub name is invalid or not currently tracked. sub_reset_all Provided mainly as a convenience, the "sub_reset_all" function will reset all the counters currently defined. Returns true. SUPPORT
Bugs should be submitted via the CPAN bug tracker, located at <http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Test-SubCalls> For other issues, or commercial enhancement or support, contact the author. AUTHOR
Adam Kennedy <adamk@cpan.org> SEE ALSO
<http://ali.as/>, Test::Builder, Test::More, Hook::LexWrap COPYRIGHT
Copyright 2005 - 2009 Adam Kennedy. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. The full text of the license can be found in the LICENSE file included with this module. perl v5.18.2 2009-04-19 Test::SubCalls(3)
All times are GMT -4. The time now is 02:56 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy