diff --git a/a1/README b/a1/README new file mode 100644 index 0000000000000000000000000000000000000000..5eb44ea89cf7e8a58c77e0e744b9c2ab932e55b1 --- /dev/null +++ b/a1/README @@ -0,0 +1,5 @@ +Prob 1 outputs the total number of directories and the total number of messages sent. + +Prob 2 outputs how many messages are in the longest thread, and all threads that are of that length. + +Prob 3 takes in a data (Year/Month/Date) and returns a message sent on that day diff --git a/a1/prob1 b/a1/prob1 new file mode 100755 index 0000000000000000000000000000000000000000..7cb4c77deb63f8f0fb26447fba65ee3d543deb94 --- /dev/null +++ b/a1/prob1 @@ -0,0 +1,13 @@ +#!/bin/bash +#Yegeon Seo + +#ARCHIVE="$PWD" + +#Number of dir +dir=$(ls -d $ARCHIVE/*/ | wc -l) + +#Number of prob +prob=$(ls -R -l $ARCHIVE/*/ | egrep -n "prob*" | wc -l ) + +#Printing output +echo -e "$dir\t$prob" diff --git a/a1/prob2 b/a1/prob2 new file mode 100644 index 0000000000000000000000000000000000000000..6894f5cce9e514923adbb16fa881dfe027c28858 --- /dev/null +++ b/a1/prob2 @@ -0,0 +1,35 @@ +#!/bin/bash +#Yegeon Seo + +#ARCHIVE=$PWD + +#placeholders +largestThread=0 +largestFile="" + +#Loop through each folder +for folder in $ARCHIVE/*/; do + if [ -d $folder ]; then + cd $folder + + #For each file in the folder, get the name of the file and the number of thread + for file in *; do + filename="${file%_*}" + numThread=$(find -name "$filename*"| wc -l) + + + #if the number of thread is greater than current largest thread, replace + if [ $numThread -gt $largestThread ]; then + largestThread=$numThread + largestFile=$filename + fi + done + cd .. + fi +done + +#print the output +printf "$largestThread\t$largestFile\n" + + + diff --git a/a1/prob3 b/a1/prob3 new file mode 100644 index 0000000000000000000000000000000000000000..623933f4d886cda107824419460079e498cdeffb --- /dev/null +++ b/a1/prob3 @@ -0,0 +1,25 @@ +#!/bin/bash +#Yegeon Seo + +#ARCHIVE="$PWD" + +#Exit if there is no argument +if [ $# == 0 ]; then + echo "No arguments!! Exiting the program/" ; exit +fi + +#Format the date +date="$3/$2/$1" + +#Search ARCHIVE using grep to get files +files=$(grep -rl $date $ARCHIVE) + +#Print matching files +for file in $files; do + echo $(basename $file) +done + + + + + diff --git a/a1/prob4 b/a1/prob4 new file mode 100644 index 0000000000000000000000000000000000000000..d7bd6b599ab7e00bc940b09e9eb372287f02405f --- /dev/null +++ b/a1/prob4 @@ -0,0 +1,27 @@ +#!/bin/bash +#Yegeon Seo + +#ARCHIVE=$PWD + +#Read all the files starting with email regular expression and store it in a temp file +grep -oErh "\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,6}\b" $ARCHIVE/* >> tempfile + +#extract hostname from the email +while read email; do + extension="${email##*@}" + echo $extension >> temp +done < tempfile + +#Sort hostmames and remove duplicateds. Order by number in descending order. +sort --ignore-case temp | uniq -cdi | sort -nr -o temp + +#Print hostnames and the number of messages sent using awk +awk '{print $2, $1}' temp + +#remove temp files made +rm temp tempfile + + + + +