LINUX.ORG.RU

Нужен скрипт на поиск и подсчет повторяющихся слов


0

0

собственно сабж, может у кого есть
нужен скрипт, который распарсит большой текст, и найдет все повторяющиеся в нем слова, в независимости от регистра
текст на русском языке

по сути. нужно просто найти в тексте, самые часто встречающиеся слова...

может у кого есть уже готовое?

★★

#!/bin/bash
# wf2.sh: Crude word frequency analysis on a text file.

# Uses 'xargs' to decompose lines of text into single words.
# Compare this example to the "wf.sh" script later on.


# Check for input file on command-line.
ARGS=1
E_BADARGS=85
E_NOFILE=86

if [ $# -ne "$ARGS" ]
# Correct number of arguments passed to script?
then
  echo "Usage: `basename $0` filename"
  exit $E_BADARGS
fi

if [ ! -f "$1" ]       # Check if file exists.
then
  echo "File \"$1\" does not exist."
  exit $E_NOFILE
fi

#####################################################
cat "$1" | xargs -n1 | \
#  List the file, one word per line. 
tr A-Z a-z | \
#  Shift characters to lowercase.
sed -e 's/\.//g'  -e 's/\,//g' -e 's/ /\
/g' | \
#  Filter out periods and commas, and
#+ change space between words to linefeed,
sort | uniq -c | sort -nr
#  Finally remove duplicates, prefix occurrence count
#+ and sort numerically.
#####################################################

#  This does the same job as the "wf.sh" example,
#+ but a bit more ponderously, and it runs more slowly (why?).

exit $?

Пример работы:

edigaryev@brick ~ $ cat quiniq 
Это просто тест. Тест, тест, тест.
edigaryev@brick ~ $ ./wf.sh quiniq 
      3 тест
      1 Это
      1 Тест
      1 просто
Взято отсюда — http://tldp.org/LDP/abs/html/moreadv.html

edigaryev ★★★★★
()
cat text.txt| tr " " "\n"|grep -v "^$"| egrep -i "[а-я]|[a-z]|[0-9]"|sort -f|uniq -c|sort -n
cat /etc/X11/xorg.conf |tr " " "\n"|egrep "[a-z]|[A-Z]|[0-9]" |grep -v "^$"|sort -f|uniq -c|sort -n|tail
      3 xserver-xorg
      4 "Configured
      4 Driver
      4 generated
      5 file
      8 the
      9 Identifier
      9 Option
     10 EndSection
     10 Section
dreamer ★★★★★
()

насколько большой текст?

anonymous
()

Где-то так:

cat IDS_SNORT.txt | col -b | tr -d '\-<:;>?!@#$%^&*()_+=.,/"' | tr ' ' '\n' | awk '{w=tolower($1); a[w]++} END {for (k in a) {print k, a[k]}}' | sort -k2n | tail -10
пример 43
include 49
можно 55
на 64
any 70
snort 72
с 90
и 98
для 107
в 157
sdio ★★★★★
()
Вы не можете добавлять комментарии в эту тему. Тема перемещена в архив.