Sponsored Content
Top Forums Shell Programming and Scripting Help me in counting records from file Post 302331442 by prashant43 on Monday 6th of July 2009 07:51:17 AM
Old 07-06-2009
Error

Quote:
Originally Posted by namishtiwari
Code:
#!/usr/bin/perl
use strict;
use warnings;
my $line;
my $log;
my $count_for_Mean_Manager;
my $count_for_Mean2_manager;
my $log_file = "sample.txt";
open (FP , $log_file) or die "Can't open '$log_file' for reading."; 
while (<FP>)
{

	if (/Mean manager/)
	{
		$count_for_Mean_Manager++;
	}
	if (/Mean2 manager/)
	{
		$count_for_Mean2_manager++;
	}
}

print "total count for Mean manager is $count_for_Mean_Manager\n";
print "otal count for Mean2 manager is $count_for_Mean2_manager\n";

Thanks
NT


Thanks a lot for your reply, but this file is havin many different Mean* fields.
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Count No of Records in File without counting Header and Trailer Records

I have a flat file and need to count no of records in the file less the header and the trailer record. I would appreciate any and all asistance Thanks Hadi Lalani (2 Replies)
Discussion started by: guiguy
2 Replies

2. UNIX for Dummies Questions & Answers

Use records from one file to delete records in another file

file_in_1: 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 file_in_2: 9 10 11 12 21 22 23 24 1 2 3 4 17 18 19 20 file_out: (5 Replies)
Discussion started by: kenneth.mcbride
5 Replies

3. Shell Programming and Scripting

Counting records with AWK

I've been working with an awk script and I'm wondeing id it's possible to count records in a file which DO NOT contain, in this instance fields 12 and 13. With the one script I am wanting to display the count for the records WITH fields 12 and 13 and a seperate count of records WITHOUT fields... (2 Replies)
Discussion started by: Glyn_Mo
2 Replies

4. Shell Programming and Scripting

Averaging all fields while counting repeated records

Hi every one; I have a 31500-line text file upon which two following tasks are to be performed: 1: Rearranging the file 2: Taking the average of each column (considering number of zeros) and output the result into a new file This is the code I've come up with: awk '(NR%3150<3150)... (0 Replies)
Discussion started by: nxp
0 Replies

5. Programming

Counting the words in a file

Please find the below program. It contains the purpose of the program itself. /* Program : Write a program to count the number of words in a given text file */ /* Date : 12-June-2010 */ # include <stdio.h> # include <stdlib.h> # include <string.h> int main( int argc, char *argv ) {... (6 Replies)
Discussion started by: ramkrix
6 Replies

6. UNIX for Dummies Questions & Answers

Grep specific records from a file of records that are separated by an empty line

Hi everyone. I am a newbie to Linux stuff. I have this kind of problem which couldn't solve alone. I have a text file with records separated by empty lines like this: ID: 20 Name: X Age: 19 ID: 21 Name: Z ID: 22 Email: xxx@yahoo.com Name: Y Age: 19 I want to grep records that... (4 Replies)
Discussion started by: Atrisa
4 Replies

7. Shell Programming and Scripting

Counting number of records with string row delimiter

HI, i have a file like this t.txt f1|_f2|_ f1|_f2|_ f1|_f2|_ as if col delimiter is |_ and row delimiter |_\n trying to count number of records using awk $ awk 'BEGIN{FS="|_" ; RS="~~\n"} {n++}END{print n} ' t.txt 7 wondering how can i count this to 3 ? thx (9 Replies)
Discussion started by: aksforum
9 Replies

8. Shell Programming and Scripting

Deleting duplicate records from file 1 if records from file 2 match

I have 2 files "File 1" is delimited by ";" and "File 2" is delimited by "|". File 1 below (3 record shown): Doc1;03/01/2012;New York;6 Main Street;Mr. Smith 1;Mr. Jones Doc2;03/01/2012;Syracuse;876 Broadway;John Davis;Barbara Lull Doc3;03/01/2012;Buffalo;779 Old Windy Road;Charles... (2 Replies)
Discussion started by: vestport
2 Replies

9. Shell Programming and Scripting

Counting the records based on condition

Hi Unix team, I have a file with 30 columns with tab delimited. I need to count the records based on column 18 & 21 data. So I cut the data from the file using awk -F"\t" '{print $18,$21}' foo.txt Following is the output: USED SEDAN USED SUV NEW SUV USED Truck USED Truck USED... (6 Replies)
Discussion started by: karumudi7
6 Replies

10. Shell Programming and Scripting

Separate records of a file on 2 types of records

Hi I am new to shell programming in unix Please if I can provide help. I have a file structure of a header record and "N" detail records. The header record will be the total number of detail records I need to split the file in 2: One for the header Another for all detail records Could... (1 Reply)
Discussion started by: jamcogar
1 Replies
DtMsgLogOpenFile(library call)											    DtMsgLogOpenFile(library call)

NAME
DtMsgLogOpenFile -- opens a log file SYNOPSIS
#include <Dt/MsgLog.h> FILE* DtMsgLogOpenFile( const char* type, char** filename_return); DESCRIPTION
The DtMsgLogOpenFile function calls fopen to open a log file with type open mode. If fopen opens a log file successfully and returns a non- NULL filename_return, DtMsgLogOpenFile calls malloc to allocate space for filename_return. DtMsgLogOpenFile then copies the log file name to filename_return. The caller must use the free function to release the space allocated for filename_return, if it is not NULL. The caller must also close the file pointer returned by DtMsgLogOpenFile. Use caution in doing this because stderr may be returned. For a description of the algorithm used to determine the log file to open, see DtMsgLogMessage(3). Note that if a log file cannot be opened, filename_return will be set to NULL. ARGUMENTS
type Specifies the file open flag. See fopen(3) for more information. filename_return Specifies the variable to receive the returned log file name. ENVIRONMENT VARIABLES
None. RESOURCES
None. ACTIONS
/MESSAGES None. ERRORS
/WARNINGS None. EXAMPLES
The following code fragment opens the log file, logs the log file name, closes the file, and frees the space allocated for the file name. char * log_file; FILE * fp = DtMsgLogOpenFile ("a+", &log_file); if (log_file) { DtMsgLogMessage (argv[0], DtMsgLogInformation, "The log file name is: %s", log_file); free (log_file); } if (fp && fp != stderr) fclose (fp); RETURN VALUE
If DtMsgLogMessage completes successfully, it returns a pointer to the opened log file. If it cannot open a log file, it returns stderr. FILES
None. SEE ALSO
DtMsgLogMessage(3), DtMsgLogSetHandler(3) DtMsgLogOpenFile(library call)
All times are GMT -4. The time now is 09:57 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy