how to count a word in a file


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting how to count a word in a file
# 8  
Old 07-10-2009
Hi vergs99,

sorry for coming back to you.....but can you please check with the below file.
the ':' sign at the end of the ora error is getting picked up.

Code:
Input File Name: 17419_1763520347_20060718042116.sms
Info - OrderId:1763520347 - timestamp:1153189280
Error 000 - Messages from oracle:ora-00001: unique constraint (MOBILE.PK_MAILORDER) violated
Error 000 - Error Internal :9001 (Oracle error): ora-00001
Info - File /usr/mobileway/router/error/default/20060718042120-1763520347-0-0-17419-0-9001.err written
Input File Name: 20060718040944-1693906198-0-0-14502-0-9098.sms
Info - OrderId:1693906198 - timestamp:1153189744
Error 000 - Messages from oracle:ora-01438: value larger than specified precision allows for this colu
Error 000 - Error Internal :9098 (Oracle error): 1438
Info - File /usr/mobileway/router/error/resendable/20060718042904-1693906198-0-0-14502-0-9098.err written
iInput File Name: 17419_1763520347_20060718042116.sms
Info - OrderId:1763520347 - timestamp:1153189280
Error 000 - Messages from oracle:ora-00001: unique constraint (MOBILE.PK_MAILORDER) violated
Error 000 - Error Internal :9001 (Oracle error): ora-00001
Info - File /usr/mobileway/router/error/default/20060718042120-1763520347-0-0-17419-0-9001.err written
Input File Name: 20060718040944-1693906198-0-0-14502-0-9098.sms
Info - OrderId:1693906198 - timestamp:1153189744
Error 000 - Messages from oracle:ora-02935: value larger than specified precision allows for this colu
Error 000 - Error Internal :9098 (Oracle error): 1438
Info - File /usr/mobileway/router/error/resendable/20060718042904-1693906198-0-0-14502-0-9098.err written
Input File Name: 17419_1763520347_20060718042116.sms
Info - OrderId:1763520347 - timestamp:1153189280
Error 000 - Messages from oracle:ora-00002: unique constraint (MOBILE.PK_MAILORDER) violated
Error 000 - Error Internal :9001 (Oracle error): ora-00001
Info - File /usr/mobileway/router/error/default/20060718042120-1763520347-0-0-17419-0-9001.err written
Input File Name: 20060718040944-1693906198-0-0-14502-0-9098.sms
Info - OrderId:1693906198 - timestamp:1153189744
Error 000 - Messages from oracle:ora-02935: value larger than specified precision allows for this colu
Error 000 - Error Internal :9098 (Oracle error): 1438
Info - File /usr/mobileway/router/error/resendable/20060718042904-1693906198-0-0-14502-0-9098.err written


Last edited by vgersh99; 07-10-2009 at 08:46 AM.. Reason: code tags, PLEASE!
# 9  
Old 07-10-2009
To keep the forums high quality for all users, please take the time to format your posts correctly.

First of all, use Code Tags when you post any code or data samples so others can easily read your code. You can easily do this by highlighting your code and then clicking on the # in the editing menu. (You can also type code tags [code] and [/code] by hand.)

Second, avoid adding color or different fonts and font size to your posts. Selective use of color to highlight a single word or phrase can be useful at times, but using color, in general, makes the forums harder to read, especially bright colors like red.

Third, be careful when you cut-and-paste, edit any odd characters and make sure all links are working property.

Thank You.

The UNIX and Linux Forums

---------- Post updated at 07:51 AM ---------- Previous update was at 07:47 AM ----------

Code:
nawk '
/ora-[0-9]/ {
    for(i=1;i<=NF;i++)
       if ( match($i,/ora-[0-9]+/)) { a[substr($i,RSTART,RLENGTH)]++; break}
}
END {
   for (i in a)
     print "Error Code : " i " Count : " a[i]
}
' file1.txt

# 10  
Old 07-10-2009
Excellent gersh99, you are brilliant. Its working fine and working fast as well.
Can you please explain your code for the benefit of users like me or plz suggest some books where in I can gain some theoritical knowledge about shell prog using nawk.

---------- Post updated at 05:48 PM ---------- Previous update was at 05:33 PM ----------

Sorry guys for not using code tags, make sure next time i use it.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

UNIX script to check word count of each word in file

I am trying to figure out to find word count of each word from my file sample file hi how are you hi are you ok sample out put hi 1 how 1 are 1 you 1 hi 1 are 1 you 1 ok 1 wc -l filename is not helping , i think we will have to split the lines and count and then print and also... (4 Replies)
Discussion started by: mirwasim
4 Replies

2. Shell Programming and Scripting

How to append word count at end of file?

Hi guys, I have to append the word count of a file at the end of the file name like this - > "filename_2345" where 2345 is the word count of "filename". How do i achieve this using one command ? I am not allowed to store the word count in a variable and then concatenate. Request your... (1 Reply)
Discussion started by: peter2312
1 Replies

3. UNIX for Dummies Questions & Answers

Taking word count from file and printing in file

hi, i am having a file which contains the below content, i need to take the word count of if and print the file name also inputfile.txt file_name1.txt,type_name1.txt file_name2.txt,type_name2.txt i would need the word count of the files like this if file_name*.txt then wc -l... (10 Replies)
Discussion started by: rohit_shinez
10 Replies

4. UNIX for Dummies Questions & Answers

How do I count how many times a specific word appear in a file (ksh)?

Hi Please can you help how do I count the number of specific characters or words that appear in a file? (8 Replies)
Discussion started by: fretagi
8 Replies

5. Shell Programming and Scripting

Count characters in a csv file and add an word.

Hello, I want to add a sentence to "post column" those who are only less than 30 characters.Thank you very much for your help. "category","title","post" "Z","Zoo","test 54325 test 45363mc." "Z","Zen","rs2w3rsj 2d342dg 2d3s4f23 d23423s23h 2s34s2423g ds232d34 2342." "Z","Zet","test4444... (3 Replies)
Discussion started by: hoo
3 Replies

6. UNIX for Dummies Questions & Answers

how to count number of times each word exist in a file

I'm trying to count the number of times each word in the file exist for example if the file has: today I have a lot to write, but I will not go for it. The main thing is that today I am looking for a way to get each word in this file with a word count after it specifying that this word has... (4 Replies)
Discussion started by: shnkool
4 Replies

7. UNIX for Dummies Questions & Answers

How to count the occurences of a specific word in a file in bash shell

Hello, I want to count the occurences of a specific word in a .txt file in bash shell. Can somebody help me pleaze?? Thanks!!! (2 Replies)
Discussion started by: mskart
2 Replies

8. Shell Programming and Scripting

How to find a count of a word within a file

Hello, I'm looking for a wait to count the number of occurrences of a certain string of characters within a file. The file that I trying to parce has segments within the file that have a header and footer to each segment and I'm trying to do a count of the header string and compare it to a count... (9 Replies)
Discussion started by: bd_joy
9 Replies

9. Shell Programming and Scripting

grep all records in a file and get a word count -perl

Hi, I have a file .. file.txt .. i need to get a total record count in the files into a $variable.. im using perl script thanks (4 Replies)
Discussion started by: meghana
4 Replies

10. Shell Programming and Scripting

Count the number of occurence of perticular word from file

I want to count the number of occurence of perticular word from one text file. Please tell me "less" command is work in ksh or not. If it is not working then instead of that which command will work. :confused: (40 Replies)
Discussion started by: rinku
40 Replies
Login or Register to Ask a Question