Find the number in the file

Thread Tools Search this Thread
Top Forums Programming Find the number in the file
# 1  
Old 10-30-2013
Find the number in the file

In my system , there are text files will be generated monthly , the file name begins with xxx , then year , month ( for example xxxxx201310.txt means Oct 2013 )

I have below command to count how many abc in the month , but it only count the number in this month .

NUMBER=$(cat xxxxx201310.txt |grep -c -s "abc" )

Could advise if I would like to have the following report , it shows the no. of abc for each month , and the total no. of abc , how to make it ? very thanks

no of abc in Oct 2013 = 111
no of abc in Nov 2013 = 222
no of abc in Dec 2013 = 333
Total no of abc = 999

Last edited by Scrutinizer; 10-30-2013 at 01:12 PM.. Reason: code tags added
# 2  
Old 10-30-2013
This might give you some idea Smilie

$ cat 1.txt

$ cat 2.txt

$ cat 3.txt

$ grep -c "abc" *.txt

And for adding name


$echo "xxxxx201310.txt" | awk 'BEGIN\
{a=substr($0,length($0)-5,2);b=substr($0,length($0)-9,4);print P[a+0],b}'

OCT 2013

Last edited by vbe; 11-05-2013 at 01:31 PM..
# 3  
Old 10-31-2013
Hi pamu ,

Thanks reply , it seems display the month only Oct 2013 , could advise how to count the no ?

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. AIX

How to find number of columns in xml file?

How to find the number of columns in xml file. i tried following command. Code: #!bin/ksh cat $1 | grep -c "</mdm:attribute>"exit 0but i am not getting accurate result which is not matching with the manual count. data format : Code: <mdm:attribute> value </mdm:attribute> No... (1 Reply)
Discussion started by: victory
1 Replies

2. Shell Programming and Scripting

find biggest number inside file

Hi, I wanna find the biggest number inside of a file this is kind of example of file: 9 11 55 then i just wanna print out the biggest number i had try sed filenale | sort -k1,1n | paste -s -d',' - but i had no success ... (7 Replies)
Discussion started by: prpkrk
7 Replies

3. Solaris

Find N number of days old file on solaris

Hi, bash-3.00$ ls -ltr total 8471258 -rw-r--r-- 1 mysql mysql 1227 Jul 7 22:33 information_schema.sql -rw-r--r-- 1 mysql mysql 479762 Jul 7 22:49 mysql.sql -rw-r--r-- 1 mysql mysql 1974789 Jul 7 22:50 youconnect.sql -rw-r--r-- 1 mysql mysql 1355... (3 Replies)
Discussion started by:
3 Replies

4. Shell Programming and Scripting

Perl find page number in a file

Hi i want to ask how can i use perl and find a word in a text file, and also telling that which page doesn't it exist? Eample: have a 10 pages text file, then i need to find 'Hello' in the file, and show that which page is it contain in. Output: Hello contains 8 times in page 1, 3, 4, 7, 10... (9 Replies)
Discussion started by: mingming88
9 Replies

5. UNIX for Dummies Questions & Answers

Find number of columns in a file

Hi all, may seem a very stupid question.but me stuck up in it for long.... How to find the number of columns in a ASCII file. EX:-Demo.lst songs 1 34 45 67 Number of columns should be 5. Regards, Anindya ;) (13 Replies)
Discussion started by: rahul26
13 Replies

6. Shell Programming and Scripting

How to find number of Cols in a file ?

Hi I have a requirement wherein the file is comma separated. Each records seems to have different number of columns, how I can detect like a row index wise, how many columns are present ? Thanks in advance. (2 Replies)
Discussion started by: videsh77
2 Replies

7. Shell Programming and Scripting

How to : Find duplicate number from file? with bash

Thanks AVKlinux (6 Replies)
Discussion started by: avklinux
6 Replies

8. Shell Programming and Scripting

How to find the number of column in the text file...?

Hi, i have text file with ~ seperated columns. it is very huge size of file, in the file sompulsary supposed to has 20 columns with ~ seperated. so how can i find if the file has 20 column in the all rows...? Sample file: APA+VU~10~~~~~03~101~101~~~APA.N O 20081017 120.00... (1 Reply)
Discussion started by: psiva_arul
1 Replies

9. Shell Programming and Scripting

How to find number of lines in a file

Hi How do I find number of lines of a file? Below commands returned 0. But, the file is showing 20 lines when I open it in editplus tool. Each line contains 601 columns. Please advise I want to incorporate some word at the begining of each of those 20 lines -Somesh $ wc -l <... (2 Replies)
Discussion started by: somesh_p
2 Replies

10. Shell Programming and Scripting

find the highest number in the file

Hi, I have a file a.txt and it has values in it Eg :- I need to read through the file and find the number that is the greatest in them all. Can any one assit me on this. Thanks (30 Replies)
Discussion started by: systemali
30 Replies
Login or Register to Ask a Question