Sponsored Content
Top Forums Shell Programming and Scripting Count same word which has come many times in single lines & pars Post 302863199 by Scrutinizer on Sunday 13th of October 2013 03:15:29 AM
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..
 

10 More Discussions You Might Find Interesting

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

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

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

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

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

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

[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

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

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. 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
tapset::ipmib(3stap)													      tapset::ipmib(3stap)

NAME
tapset::ipmib - systemtap ipmib tapset DESCRIPTION
ipmib_remote_addr Get the remote ip address See function::ipmib_remote_addr(3stap) for details. ipmib_local_addr Get the local ip address See function::ipmib_local_addr(3stap) for details. ipmib_tcp_remote_port Get the remote tcp port See function::ipmib_tcp_remote_port(3stap) for details. ipmib_tcp_local_port Get the local tcp port See function::ipmib_tcp_local_port(3stap) for details. ipmib_get_proto Get the protocol value See function::ipmib_get_proto(3stap) for details. ipmib.InReceives Count an arriving packet See probe::ipmib.InReceives(3stap) for details. ipmib.InNoRoutes Count an arriving packet with no matching socket See probe::ipmib.InNoRoutes(3stap) for details. ipmib.InAddrErrors Count arriving packets with an incorrect address See probe::ipmib.InAddrErrors(3stap) for details. ipmib.InUnknownProtos Count arriving packets with an unbound proto See probe::ipmib.InUnknownProtos(3stap) for details. ipmib.InDiscards Count discarded inbound packets See probe::ipmib.InDiscards(3stap) for details. ipmib.ForwDatagrams Count forwarded packet See probe::ipmib.ForwDatagrams(3stap) for details. ipmib.OutRequests Count a request to send a packet See probe::ipmib.OutRequests(3stap) for details. ipmib.ReasmTimeout Count Reassembly Timeouts See probe::ipmib.ReasmTimeout(3stap) for details. ipmib.ReasmReqds Count number of packet fragments reassembly requests See probe::ipmib.ReasmReqds(3stap) for details. ipmib.FragOKs Count datagram fragmented successfully See probe::ipmib.FragOKs(3stap) for details. ipmib.FragFails Count datagram fragmented unsuccessfully See probe::ipmib.FragFails(3stap) for details. SEE ALSO
function::ipmib_remote_addr(3stap), function::ipmib_local_addr(3stap), function::ipmib_tcp_remote_port(3stap), function::ipmib_tcp_local_port(3stap), function::ipmib_get_proto(3stap), probe::ipmib.InReceives(3stap), probe::ipmib.InNoRoutes(3stap), probe::ipmib.InAddrErrors(3stap), probe::ipmib.InUnknownProtos(3stap), probe::ipmib.InDiscards(3stap), probe::ipmib.ForwDatagrams(3stap), probe::ipmib.OutRequests(3stap), probe::ipmib.ReasmTimeout(3stap), probe::ipmib.ReasmReqds(3stap), probe::ipmib.FragOKs(3stap), probe::ipmib.FragFails(3stap), stap(1), stapprobes(3stap) IBM
--- tapset::ipmib(3stap)
All times are GMT -4. The time now is 10:19 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy