Browse Source

Merge branch 'master' of gitea.shuishan.net.cn:10215501433/Computer-Systems-Labs

master
仲韦萱 1 year ago
parent
commit
504eae2f4e
6 changed files with 166 additions and 0 deletions
  1. +21
    -0
      10215501451.md
  2. +57
    -0
      lab1/10215501411.sh
  3. +15
    -0
      lab1/10215501415.sh
  4. +40
    -0
      lab1/10215501417.sh
  5. +10
    -0
      lab1/10215501418.sh
  6. +23
    -0
      lab1/10215501435.sh

+ 21
- 0
10215501451.md View File

@ -0,0 +1,21 @@
touch text1.txt
for i in `seq 50000`;do echo $RANDOM | md5sum | cut -c 1-9 ;done >> text1.txt
export LC_ALL=C
sort text1.txt | uniq
sort -n text1.txt | uniq
sort text1.txt | uniq > letter.txt
sort -n text1.txt | uniq >> number.txt
echo -e "computer\ndata\nscience\nengineering\nscience\nengineeringc\ncomputer\ncomputer\necnu\ndata" > text2.txt
grep computer text2.txt
grep -c computer text2.txt

+ 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

+ 15
- 0
lab1/10215501415.sh View File

@ -0,0 +1,15 @@
#两个字符串文件均由python生成
#按数字排序
#覆盖写
cat hw1.txt | sort | uniq -d > 1.txt
cat hw1.txt | sort -n | uniq -d > 1.txt
#追加写
cat hw1.txt | sort | uniq -d >> 2.txt
cat hw1.txt | sort -n | uniq -d >> 2.txt
#找出指定字符串
grep computer hw1-2.txt
grep -c computer hw1-2.txt

+ 40
- 0
lab1/10215501417.sh View File

@ -0,0 +1,40 @@
#!/bin/bash
#生成50000行包含字母与数字的文件
#需要从urandom中读取字母与数字,共50000次循环,大概需要5-10min左右。
for((i = 0; i < 50000; i++))
do
head -c 50 /dev/urandom | tr -dc A-Za-z0-9 >> RandFile;
echo -e \ >> RandFile;
done
#按字母排序
sort RandFile | uniq;
#按数字排序
sort -n RandFile | uniq;
#重定向到SortedFile1
sort RandFile | uniq >> SortedFile1;
#重定向到SortedFile2
sort -n RandFile >> SortedFile2;
#统计RandFile中 ab 出现的次数
grep -o ab RandFile|wc -l;
#git push到码园
git init #初始化
git add . #添加文件夹下所有文件
git commit -m "lab1 first commit" #把添加的文件提交到远程版本库
git remote add origin https://gitea.shuishan.net.cn/10215501417/csapp.git #建立远程连接
git push -u origin master #上传代码
#fork工作流:
#首先 fork目标仓库到自己的远程仓库
#再git clone到自己的仓库
git clone https://gitea.shuishan.net.cn/10215501417/Computer-Systems-Labs.git
#创建一个分支
git checkout -b hw
#将代码文件上传
git add 10215501417.sh
git commit -m "10215501417's cmommit"
#然后再发起一个pr到目标仓库

+ 10
- 0
lab1/10215501418.sh View File

@ -0,0 +1,10 @@
python 1.py > 1.1.txt
sort -d 1.1.txt > 1.2.txt --unique
sort --numeric-sort 1.1.txt > 1.2.txt --unique
sort -d 1.1.txt >> 1.3.txt --unique
sort --numeric-sort 1.1.txt >> 1.3.txt --unique
python 2.py > 2.txt
grep "computer" 2.txt
grep -c "computer" 2.txt

+ 23
- 0
lab1/10215501435.sh View File

@ -0,0 +1,23 @@
#!/bin/bash
#生成50行随机字符串
for i in {1..50}
do
echo $RANDOM | md5sum | cut -c 1-9 >> random_50.txt
done
#将上述50行随机的字符串循环100次,得到5000行有规律的字符串
times=1
while((times<=100))
do
head -n 50 random_50.txt >> random_5000.txt
times=`expr $times + 1`
done
#以覆盖写的方式,字母排序,输出unique行
sort -u random_5000.txt > alph.txt
#以覆盖写的方式,数字排序,输出unique行
sort -u -n random_5000.txt > number.txt
#以追加写的方式,字母排序,输出unique行
sort -u random_5000.txt >> alph.txt
#以追加写的方式,数字排序,输出unique行
sort -u -n random_5000.txt >> number.txt
#已经生成一个含有60个Computer的letter文件
grep -c "Computer" letter.txt

Loading…
Cancel
Save