Record count based on a keyword in the records


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Record count based on a keyword in the records
# 1  
Old 03-03-2009
Record count based on a keyword in the records

Hi,

Am having files with many records, i need to count and display the number of records based on the keyword in one of the column of the records.

for e.g THE FILE CONTAINS TWO RECORDS LIKE.

200903031143150 0 1236060795054357lessrv1 BSNLSERVICE1 BSNLSERVICE1 2128 FRAMEWORK slir 0 SUCCESS 919445393337 477 352 WGS84



200903031143150 0 1236060795054357lessrv1 RTMS RTMS 2128 FRAMEWORK slir 0 SUCCESS 919445393337 477 352 WGS84


I NEED TO COUNT THE NO OF RECORDS BASED ON COLUMN NO 4(BSNLSERVICE1) AND DISPLAY

CAN ANY ONE HELP ME OUT

AEMUNATHAN
# 2  
Old 03-03-2009
cat myfile | cut -f4 -d" " | grep mytext | wc -l

myfile will be the name of file in which you are searching
4 in f4 represents column 4
mytext is what I am searching
Regards
Puneet Khurana
# 3  
Old 03-03-2009
am getting zero as the result...but records are there

cat 1236062198899.7372.tmp | cut -f5 -d "" | grep BSNLSERVICE1 | wc -l
0

cat 1236062198899.7372.tmp | cut -f4 -d "" | grep BSNLSERVICE1 | wc -l
0

Last edited by aemunathan; 03-03-2009 at 03:24 AM..
# 4  
Old 03-03-2009
Code:
$ cat log
200903031143150 0 1236060795054357lessrv1 BSNLSERVICE1 BSNLSERVICE1 2128 FRAMEWORK slir 0 SUCCESS 919445393337 477 352 WGS84
200903031143150 0 1236060795054357lessrv1 RTMS RTMS 2128 FRAMEWORK slir 0 SUCCESS 919445393337 477 352 WGS84

$ awk '{sum[$4]++;}END{for(i in sum) {print i, sum[i]}}' log
RTMS 1
BSNLSERVICE1 1

# 5  
Old 03-03-2009
thanks ...its working fine
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

awk to count start and end keyword in a line

Hello fellow awkers and seders: need to figure out a way to ensure a software deployment has completed by checking its trace file in which I can store the deployment results as follows: echo $testvar ===== Summary - Deploy Result - Start ===== ===== Summary - Deploy Result - End =====... (1 Reply)
Discussion started by: ux4me
1 Replies

2. Shell Programming and Scripting

Serach a keyword based on last updated

Hi, Can you guys help in writing script based upon my requirement. The requirement is : Th script should poll or sniff an log file every minute or every second. The log file name is "license.txt" In the log file if it founds "not valid" then it should send mail to a group. the logic... (3 Replies)
Discussion started by: rockingvj
3 Replies

3. Shell Programming and Scripting

count the unique records based on certain columns

Hi everyone, I have a file result.txt with records as following and another file mirna.txt with a list of miRNAs e.g. miR22, miR123, miR13 etc. Gene Transcript miRNA Gar Nm_111233 miR22 Gar Nm_123440 miR22 Gar Nm_129939 miR22 Hel Nm_233900 miR13 Hel ... (6 Replies)
Discussion started by: miclow
6 Replies

4. Shell Programming and Scripting

Merge file lines based off of keyword

Hello Everyone, I have two files I created in a format similar to the ones found below (character position is important): File 1: 21 Cat Y N S Y Y N N FOUR LEGS TAIL WHISKERS 30 Dog N N 1 Y Y N N FOUR LEGS TAIL 33 Fish Y N 1 Y Y N N FINS 43 CAR Y N S Y Y N N WHEELS DOORS... (7 Replies)
Discussion started by: jl487
7 Replies

5. Shell Programming and Scripting

Multiple records based on ';' in the record

Hi All, I have a *.csv files in a die /pro/lif/dow, (pipe delimiter file), these files are having 8 columns and 6 column(CDR_LOGIC) records are populated as below, I need to incorporate the below logic in all the *.csv files. 11||:ColumnA||:ColumnB 123||:ColumnA IIF(:ColumnA = :ColumnC then... (6 Replies)
Discussion started by: shruthidwh
6 Replies

6. Shell Programming and Scripting

using awk to count no of records based on conditions

Hi I am having files with date and time stamp as the folder names like 200906051400,200906051500,200906051600 .....hence everyday 24 files will be generated i need to do certain things on this 24 files daily file contains the data like 200906050016370 0 1244141195225298lessrv3 ... (13 Replies)
Discussion started by: aemunathan
13 Replies

7. Shell Programming and Scripting

Based on num of records in file1 need to check records in file2 to set some condns

Hi All, I have two files say file1 and file2. I want to check the number of records in file1 and if its atleast 2 (i.e., 2 or greater than 2 ) then I have to check records in file2 .If records in file2 is atleast 1 (i.e. if its not empty ) i have to set some conditions . Could you pls... (3 Replies)
Discussion started by: mavesum
3 Replies

8. Shell Programming and Scripting

replaying a record count with another record count

i use unix command to take the record count for a file1 awk 'END{print NR}' filename i already have a file2 which conatin the count like ... .. rec_cnt=100 .. .. I want to replace the record in the file2 using the record i take from file1. suggest me some simple ways of doing it... (2 Replies)
Discussion started by: er_zeeshan05
2 Replies

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

10. UNIX for Dummies Questions & Answers

How to count the record count in an EBCDIC file.

How do I get the record count in an EBCDIC file on a Linux Box. :confused: (1 Reply)
Discussion started by: oracle8
1 Replies
Login or Register to Ask a Question