gpt4 book ai didi

file - 如何在同一时间shell中读取两个文件

转载 作者:行者123 更新时间:2023-12-05 09:24:07 24 4
gpt4 key购买 nike

我有两个文件,

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

我想做的是创建另一个文件,其中只有在文件 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

所以我在 temp.txt 文件中有符合文件 A 标准的人,但我的问题是我如何将他们与文件名 2 中的人进行比较并从中创建“结果”?我试过两个 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

关于file - 如何在同一时间shell中读取两个文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15642981/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com