![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !! |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| displaying $ in data | ammu | UNIX for Dummies Questions & Answers | 2 | 02-19-2008 11:00 AM |
| displaying the users | needyourhelp | UNIX for Dummies Questions & Answers | 1 | 09-12-2007 10:37 PM |
| displaying with ls | vivekshankar | UNIX for Dummies Questions & Answers | 2 | 05-23-2005 12:46 PM |
| Displaying what a command is doing/has done | quantumechanix | UNIX for Dummies Questions & Answers | 1 | 07-02-2003 05:40 AM |
| displaying date | minazk | Shell Programming and Scripting | 7 | 11-14-2002 08:04 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Hi guys,
i need to search the most commonly occuring words in a file and display their counts of about 30000 words and the words shud not be of typ specified in file 2 e. words like is,for,the,an,he,she etc... k. file1: ALICE was beginning to get very tired of sitting by her sister on the bank and of having nothing to do: once or twice she had peeped into the book her sister was reading, but it had no pictures or conversations in it, "and what is the use of a book," thought Alice, "without pictures or conversations?' So she was considering, in her own mind (as well as she could, for the hot day made her feel very sleepy and stupid), whether the pleasure of making a daisy-chain would be worth the trouble of getting up and picking the daisies, when suddenly a White Rabbit with pink eyes ran close by her. file2: was to get of by her on the etc.... output: ALICE : 1 begining : 1 etc... Cud u help me with this |
| Forum Sponsor | ||
|
|
|
|||
|
This is actually quite a famous problem. I quote verbatim from "Classic Shell Scripting"
Quote:
Code:
#! /bin/sh
# Read a text stream on standard input, and output a list of
# the n (default: 25) most frequently occurring words and
# their frequency counts, in order of descending counts, on
# standard output.
#
# Usage:
# wf [n]
tr -cs A-Za-z\' '\n' |
# Replace nonletters with newlines
tr A-Z a-z |
#Map uppercase to lowercase
sort |
#Sort the words in ascending order
uniq -c |
#Eliminate duplicates, showing their counts
sort -k1,1nr -k2 |
#Sort by descending count, and then by ascending word
sed ${1:-25}q
#Print only the first n (default: 25) lines
|
|||
| Google The UNIX and Linux Forums |