Jac*_*son 1 unix printing shell file
我有两个档案
A
john 1 2 3 4 5 6 7
Ely 10 9 9 9 9 9 9
Maria 3 5 7 9 2 1 4
Rox 10 10 10 10 10 10 10
B
john 7.5
Ely 4.5
Maria 3,7
Rox 8.5
Run Code Online (Sandbox Code Playgroud)
我想做的是创建另一个文件,其中仅文件A的平均分数大于或等于8.5,在B中的分数也等于或大于8.5,因此在我的示例中,C文件将仅包含Rox,因为只有她符合条件。
我有这个
#shell program
echo "Fiserul are numele $1"
filename=$1
filename2=$2
echo "">temp.txt
touch results
compara="8.5"
cat $filename | while read -r line
do
nota=0
media=0
echo " $line"
rem=$( echo "$line"| cut -f 2- -d ' ')
for word in $rem
do
echo "$word"
nota=$(($nota+$word))
echo "Nota=$nota"
done
media=$(($nota / 7))
if [ "$(echo $media '>=' $compara | bc -l)" -eq 1 ];
then
nume=$( echo "$line"| cut -f 1 -d ' ')
echo "$nume $media" >> temp.txt
fi
echo "Media : $media"
done
cat $filename2 | while read -r line
do
Run Code Online (Sandbox Code Playgroud)
所以我在temp.txt文件中有满足文件A标准的人员,但我的问题是我如何将他们与filename2中的人员进行比较并从中创建“结果”?我尝试了两个while循环,但出现错误,有人可以帮忙吗?谢谢!
如果您确实想同时读取两个文件(这似乎不是您的实际问题,但join确实是您执行工作的正确工具),则可以在不同的FD上打开它们:
while IFS= read -r -u 4 line1 && IFS= read -r -u 5 line2; do
echo "Line from first file: $line1"
echo "Line from second file: $line2"
done 4<file1 5<file2
Run Code Online (Sandbox Code Playgroud)