final script to perform data processing

This commit is contained in:
Kuba 2023-03-21 22:30:42 +01:00
parent 3e0ee10fd9
commit 2afff87ba0

23
analysis/advanced.sh Executable file
View File

@ -0,0 +1,23 @@
#!/bin/bash
#count comas & spaces
echo "Ammount of comas"
bzcat $1 | tr '[:upper:]' '[:lower:]' | tr -cd ',' | wc -c
echo "Ammount of dots"
bzcat $1 | tr '[:upper:]' '[:lower:]' | tr -cd '.' | wc -c
echo "Ammount of white spaces"
bzcat $1 | tr '[:upper:]' '[:lower:]' | tr -cd ' ' | wc -c
echo "Ammount of line breaks"
bzcat $1 | tr '[:upper:]' '[:lower:]' | tr -cd '\n' | wc -c
#calculate no occurances of each word
echo "calculate no occurances of each word"
bzcat $1 | tr -s '[:punct:][:space:]' '\n' | grep -E "^[^\x00-\x7F]*[[:alpha:]][^\x00-\x7F]*$" | sort | uniq -c | sort -nr > word_freq.txt
# Convert text to lowercase and replace non-alphabetic characters with spaces, then use awk to print bigrams
echo "calculate bigrams frequency in text"
bzcat $1 | tr '[:upper:]' '[:lower:]' | tr -cs '[:alpha:]' ' ' | fold -w 1000 | sed -e 's/\b\s\+\b/ /g' | awk '{for(i=1;i<NF;i++)print $i,$(i+1)}' | sort | uniq -c > bigram_freq.txt
#calculate no occurances of words depending on length
echo "calculate no occurances of words depending on length"
bzcat $1 | tr -cs '[:alnum:]' ' ' | tr ' ' '\n' | awk '{print length}' | sort -n | uniq -c > len_freq.txt