text pattern count statistic


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting text pattern count statistic
# 1  
Old 07-03-2011
text pattern count statistic

Hi all

is it possible to have a text pattern count statistic by using simple script instead count it one by one ?

apple
apple
boy
boy
boy
boy
cat
cat
cat
cat
cat
dog....
...

apple = 3
boy = 4
cat = 5
dog .....
# 2  
Old 07-03-2011
If there is only one word per line, then this should work:
Code:
awk '{a[$0]++}END{for (i in a){print i" = "a[i]}}' file

# 3  
Old 07-03-2011
Or shorter:
Code:
sort file | uniq -c

This User Gave Thanks to pludi For This Post:
# 4  
Old 07-03-2011
-bash-3.2# sort 5.txt | uniq -c
2 apple
4 boy
5 cat

Image pludi thanks.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Pattern count in file

hi , I have a below file which contain as Use descriptive thread titles when posting Urgent. For example, do not post questions with subjects like "Help Me!", "Urgent Urgent Urgent" . or "Doubt". Post subjects like "Execution Problems with Cron" or "Help with Backup Shell Script".... (7 Replies)
Discussion started by: Jewel
7 Replies

2. Shell Programming and Scripting

Identify file pattern, take count of pattern, then act

Guys - Need your ideas on a section of code to finish something up. To make a long story short, I'm parsing a print output file that goes to pre-printed forms. I'm intercepting it, parsing it, formatting it, cutting it up into individual pages, grabbing the text I want in zones, building an... (3 Replies)
Discussion started by: ampsys
3 Replies

3. Shell Programming and Scripting

Count Pattern

I need to count the total no of SIN*Y and SIN*N patterns from the below file , The file does not have a record terminators , data in the file is streamed i.e. one line I want to put this count in xml structure <count> <value>$totalcount</value> </count> Tried the following awk... (13 Replies)
Discussion started by: techedipro
13 Replies

4. Shell Programming and Scripting

Search for a pattern in a String file and count the occurance of each pattern

I am trying to search a file for a patterns ERR- in a file and return a count for each of the error reported Input file is a free flowing file without any format example of output ERR-00001=5 .... ERR-01010=10 ..... ERR-99999=10 (4 Replies)
Discussion started by: swayam123
4 Replies

5. UNIX for Dummies Questions & Answers

Count pattern occurences

hi, I have a text..and i need to find a pattern in the text and count to the no of times the pattern occured. i have used grep command ..but the problem is , it shows the occurrences of the pattern but doesn't count no of times the pattern occuries. (5 Replies)
Discussion started by: nvnni
5 Replies

6. Shell Programming and Scripting

Filename pattern count

Hi I have the following files in a directory - ds_pl_W_Test ds_pl_list_Test ds_pl_list_Test ds_pl_listl_Test ds_pl_file_Test ds_pl_xx_Test I would like to count the number files in the directory that contain the word "list" I tried the following but it returns zero - ... (3 Replies)
Discussion started by: Prega
3 Replies

7. Shell Programming and Scripting

Count the number of occurrences of a pattern between each occurrence of a different pattern

I need to count the number of occurrences of a pattern, say 'key', between each occurrence of a different pattern, say 'lu'. Here's a portion of the text I'm trying to parse: lu S1234L_149_m1_vg.6, part-att 1, vdp-att 1 p-reserver IID 0xdb registrations: key 4156 4353 0000 0000 ... (3 Replies)
Discussion started by: slipstream
3 Replies

8. Shell Programming and Scripting

sed: Find start of pattern and extract text to end of line, including the pattern

This is my first post, please be nice. I have tried to google and read different tutorials. The task at hand is: Input file input.txt (example) abc123defhij-E-1234jslo 456ujs-W-abXjklp From this file the task is to grep the -E- and -W- strings that are unique and write a new file... (5 Replies)
Discussion started by: TestTomas
5 Replies

9. Shell Programming and Scripting

nawk-how count the number of occurances of a pattern, when don't know the pattern

I've written a script to count the total size of SAN storage LUNs, and also display the LUN sizes. From server to server, the LUNs sizes differ. What I want to do is count the occurances as they occur and change. These are the LUN sizes: 49.95 49.95 49.95 49.95 49.95 49.95 49.95 49.95... (2 Replies)
Discussion started by: cyber111
2 Replies

10. Shell Programming and Scripting

How to count pattern in column

Hi, I have another problem here on Bash. Assume I have an output file containing two columns which the second one contains :- abc`dgdf`sdfdg` dfgfg```ssd` I would like to count the "`" characters for each line (which is first column). I am wondering what command can I used other than... (12 Replies)
Discussion started by: ahjiefreak
12 Replies
Login or Register to Ask a Question