Browse Source

Merge pull request '10215501411 Wu Mianzhi Lab1' (#14) from 10215501411/Computer-Systems-Labs:master into master

Reviewed-on: https://gitea.shuishan.net.cn/52265903006/Computer-Systems-Labs/pulls/14
master
朱君鹏 1 year ago
parent
commit
795d1dae71
1 changed files with 57 additions and 0 deletions
  1. +57
    -0
      lab1/10215501411.sh

+ 57
- 0
lab1/10215501411.sh View File

@ -0,0 +1,57 @@
SAMESTR="ThisIsTheSameString" #Same String for uniq
readonly SAMESTR
##
# Get random integar between 1 and 100
##
function getRandomName(){
rnd=`expr $RANDOM % 64 + 1`
return $rnd
}
##
# Get random string, first parametar is length
##
function getRandomString(){
openssl rand -base64 $1
}
function generate(){
size=500
i=0
while(( $i < $size ))
do
getRandomName
length=$?
#echo "START"
if [[ $length -ge 1 && $length -le 25 ]]
then
echo $SAMESTR
else
echo `getRandomString $length`
fi
let "i++"
done
}
function sortByASCII(){
generate | sort | uniq -u
}
function sortByNumeric(){
generate | sort --numeric-sort | uniq -u
}
echo "Overwrite lines:" > resultASCII #this line should not appear in output file
sortByASCII > resultASCII
echo "Append lines:" >> resultASCII #this line should appear in output file
sortByASCII >> resultASCII
echo "Overwrite lines:" > resultNumeric #this line should not appear in output file
sortByNumeric > resultNumeric
echo "Append lines:" >> resultNumeric #this line should appear in output file
sortByNumeric >> resultNumeric
echo "Number of same string in file:"
generate > randomLines
grep --only-matching $SAMESTR < randomLines | wc --lines

Loading…
Cancel
Save