Quellcode durchsuchen

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
朱君鹏 vor 2 Jahren
Ursprung
Commit
795d1dae71
1 geänderte Dateien mit 57 neuen und 0 gelöschten Zeilen
  1. +57
    -0
      lab1/10215501411.sh

+ 57
- 0
lab1/10215501411.sh Datei anzeigen

@ -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

Laden…
Abbrechen
Speichern