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


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Count same word which has come many times in single lines & pars
# 1  
Old 10-13-2013
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 ==

"
Code:
Thanks heman thanks thanks
Thanks heman
thanks man

"

So resullt should be

Code:
Thanks = 5
heman=2
man = 1

thanks in advance Smilie

Moderator's Comments:
Mod Comment Please use code tags for code and data


---------- Post updated at 02:01 AM ---------- Previous update was at 01:48 AM ----------

nm, the below worked ..

Code:
/root #tr ' ' '\12' <test | tr 'A-Z' 'a-z' | sed s/[^a-zA-Z]//g | sort | uniq -c | sort -nr
    334
     76 a
     69 volume
     48 the
     39 lvm
     38 disk
     36 vxvm
     36 group
     29 to
     26 logical
     19 volname
     19 devvolgrp
     17 volumes
     16 in
     15 or
     14 diskgroup
     13 remove
     13 devvolgrplvolname
...

---------- Post updated at 02:02 AM ---------- Previous update was at 02:01 AM ----------

I will use code tag !!!

tx

Last edited by Scrutinizer; 10-13-2013 at 04:16 AM.. Reason: code tags
# 2  
Old 10-13-2013
It would start out simple, something like:
Code:
awk '{for(i=1; i<=NF; i++) A[tolower($i)]++} END{for(i in A) print i " = "  A[i]}'  file

But then it would get more complicated. If you only use the lowercase form then what do you do with a word like "I" or what do you do with names that start with an uppercase letter, or for instance with "Mr. d'Arcy". You'd want to exclude dots and comma's that cling to words. Is the "-" part of a word or isn't it. Is a number a word, or a combination of a word and a number? Etc. You could make an approximation, for example:
Code:
awk -F'[^-_[:alnum:]]*' '{for(i=1; i<=NF; i++) if ($i!="") A[tolower($i)]++} END{for(i in A) print i " = "  A[i]}' file

But to cater for all corner cases is likely going to be a bit complex..
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Get count of multiple word in single command

Hello Experts, I have a log file that contains 4 different type of exception : 1- Exception 2- Fatal 3- Error 4- Exec My requirement is to find count of each type of exception, i tried using combination of -E and -C but that doesn't seems to be working : grep -ec 'Exception' -ec... (4 Replies)
Discussion started by: mukulverma2408
4 Replies

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

3. Shell Programming and Scripting

awk to find lines containing word that occur multiple times

i have a script that scans a log file every 10 minutes. this script remembers the last line of the log and then uses it to continue monitoring the log when it runs again 10 minutes later. the script searches the log for a string called MaxClients. now, how can i make it so that when the... (7 Replies)
Discussion started by: SkySmart
7 Replies

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

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

6. Shell Programming and Scripting

Extract single word from lines

Hi I have a huge line like the following: this word and many other words AA122134 other and other words and AA224466 and other other other other word AA667210 words I only want extract the words AA?????? and put them in a column, how could i do ? thx so much! (7 Replies)
Discussion started by: AdminLew
7 Replies

7. Shell Programming and Scripting

Word count of lines ending with certain word

Hi all, I am trying to write a command that can help me count the number of lines in the /etc/passwd file ending in bash. I have read through other threads but am yet to find one indicating how to locate a specifc word at the end of a line. I know i will need to use the wc command but when i... (8 Replies)
Discussion started by: warlock129
8 Replies

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

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

10. UNIX for Dummies Questions & Answers

search& count for the occurence of a word

Greetings, I need to search and count all the occurences of a word in all the files in a directory. Any suggestions greatly appreciated. Thanks (1 Reply)
Discussion started by: skoppana
1 Replies
Login or Register to Ask a Question