Sponsored Content
Top Forums UNIX for Dummies Questions & Answers how to count number of times each word exist in a file Post 302579539 by shnkool on Tuesday 6th of December 2011 02:29:39 AM
Old 12-06-2011
Question 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 occured that number of times in the whole file.

today-->2
I-->3
have-->1
a-->3
lot-->1
write-->1
but-->1
will-->1
not-->1


and so on


I used tr to separate each word in a line but I'm not sure how I'm going to look for each word
 

10 More Discussions You Might Find Interesting

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

2. Shell Programming and Scripting

TO find the word which occurs maximum number of times

Hi Folks !!!!!!!!!!!!!!!!!!! My Requirement is............. i have a input file: 501,501.chan 502,502.anand 503,503.biji 504,504.raja 505,505.chan 506,506.anand 507,507.chan and my o/p should be chan->3 i.e. the word which occurs maximum number of times in a file should be... (5 Replies)
Discussion started by: aajan
5 Replies

3. Shell Programming and Scripting

Count number of digits in a word

Hi all Can anybody suggest me, how to get the count of digits in a word I tried WORD=abcd1234 echo $WORD | grep -oE ] | wc -l 4 It works in bash command line, but not in scripts :mad: (12 Replies)
Discussion started by: ./hari.sh
12 Replies

4. Shell Programming and Scripting

Looking for a single line to count how many times one character occurs in a word...

I've been looking on the internet, and haven't found anything simple enough to use in my code. All I want to do is count how many times "-" occurs in a string of characters (as a package name). It seems it should be very simple, and shouldn't require more than one line to accomplish. And this is... (2 Replies)
Discussion started by: Shingoshi
2 Replies

5. Shell Programming and Scripting

scripting - write a script that will count the number of times a particular word

hello everyone, I'm trying to learn some scripts but i cant get my head around two of them. 1. how can i write a script that will count the number of times a particular word is used in file? 2. how can i make a script that will take me to a web page from unix? if anyone could help it... (3 Replies)
Discussion started by: BigTool4u2
3 Replies

6. Shell Programming and Scripting

Print a word specific number of times

Hi All, I wanted to know if there is a shell command to print a word n number of times The Input File is : Cat 4 Bat 3 Zall 1 Kite 2 Output File required is : Cat Cat Cat Cat Bat Bat Bat Zall Kite (4 Replies)
Discussion started by: sam_2921
4 Replies

7. Shell Programming and Scripting

Match and count the number of times

ile1 Beckham Ronaldo file2 Beckham Beckham_human Ronaldo Ronaldo_spain Ronaldo Ronaldo_brazil Beckham Beckham_manch Zidane Zidane_Fran Rooney Rooney_Eng Output shud be (1 Reply)
Discussion started by: cdfd123
1 Replies

8. UNIX for Dummies Questions & Answers

[Solved] Count amount of times of appearing of character before a word?

Hello Is there a way to calculate how many times a particular symbol appeared in a string before a particular word. Desktop/Myfiles/pet/dog/puppy So, I want to count number of occurence of"/" in this directory before the word dog lets say. Cheers, Bob (3 Replies)
Discussion started by: FUTURE_EINSTEIN
3 Replies

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

10. Shell Programming and Scripting

Count same word which has come many times in single lines & pars

can i get a simple script for , Count same word which has come many times in single lines & pars Eg file would be == "Thanks heman thanks thanks Thanks heman thanks man" So resullt should be Thanks = 5 heman=2 man = 1 thanks in advance :) Please use code tags for code and... (1 Reply)
Discussion started by: heman96
1 Replies
acctcms(8)						      System Manager's Manual							acctcms(8)

NAME
acctcms - Produces command usage summaries from accounting records SYNOPSIS
acctcms [-acjnspot] file ... FLAGS
Displays output in ASCII summary format rather than the default binary format. The acctcms command sorts its output in descending order according to total K-core minutes. The unit K-core minutes is the amount of storage used (in kilobytes) multiplied by the amount of time the buffer was in use. The hog factor is the total CPU time divided by the total real time. The ASCII summary output format has the fol- lowing headings: The COMMAND NAME column specifies the name of the command. Because only object modules are reported by the accounting system, the sh command entry specifies the entry for all shell processes, regardless of their actual names. The NUMBER CMDS column speci- fies the total number of command invocations during the accounting period. The TOTAL KCOREMIN column combines the amount of memory used and the length of time used. Memory is specified in kilobyte blocks, and time is specified in minutes. The TOTAL CPU-MIN column specifies the total CPU time needed to process the command the number of times specified in the NUMBER CMDS column. The TOTAL REAL-MIN column speci- fies the total number of real-time minutes needed to process the command the number of times specified in the NUMBER CMDS column. The MEAN SIZE-K column specifies the average amount of memory in kilobytes used to process the command the number of times specified in the NUMBER CMDS column. The MEAN CPU-MIN column specifies the average amount of CPU time that the command used each time it was processed. The mean CPU minutes are obtained by dividing the total CPU minutes by the total number of commands. The HOG FACTOR column specifies the CPU time needed to process the command the number of times specified in the NUMBER CMDS column with respect to the time required to process all com- mands. This value shows the ratio of system availability to system utilization. The CHARS TRANSFD column specifies the total number of characters that were read or written when the command was processed the number of times specified in the NUMBER CMDS column. The BLOCKS READ column specifies the number of file system blocks (1 block is equivalent to 1 kilobyte) that were read when the command was processed the number of times specified in the NUMBER CMDS column. The number of blocks read may not correspond with the number of characters trans- ferred. Sorts in descending order according to total CPU time rather than total K-core minutes. Combines all commands called only once in the column specified by "***other" in the COMMAND NAME column. Sorts in descending order according to the number of times each command was called. Displays a command summary of nonprime-time commands. Displays a command summary of prime-time commands. Assumes that any file specified after this flag is in binary format. Processes all records as total accounting records. The default binary format splits each heading into prime-time and nonprime-time parts. DESCRIPTION
The acctcms command outputs data in a format called TOTAL COMMAND SUMMARY. This command reads each file specified, combines and sorts all records for identically named processes, and writes them in a binary format to the output device. Files are usually organized in the acct file format. When you specify the -o and -p flags together, the acctcms command produces a summary report that combines commands processed during both prime and nonprime time. All the output summaries specify total usage, except for the number of times run, CPU minutes, and real minutes, which are split into prime-time and nonprime-time minutes. EXAMPLES
To collect command accounting records from one or more source files into a command summary file called today and to maintain a running total summary of commands in a file called cmtotal, add the following lines to an accounting shell script: acctcms [source File(s) ....] > today cp total prev_tot acctcms -s today prev_tot > cmtotal acctcms -a -s cmtotal First, the acctcms command is used to redirect command records in File(s) that you specify to a file called today. Next, the old total com- mand summary file is renamed prev_tot. Then, the command summary records that are collected in the today and the prev_tot files are redi- rected to a new command summary file called cmtotal. These are all binary files. The last acctcms command outputs to the default output device the contents of the cmtotal file in the ASCII default command summary format previously described, so that the report may be dis- played. FILES
Specifies the command path. This is where prime time is set. Accounting header files that define formats for writing accounting files. RELATED INFORMATION
Commands: acct(8), runacct(8) Functions: acct(2) delim off acctcms(8)
All times are GMT -4. The time now is 06:21 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy