linux shell两个文件数值相加

linux shell两个文件数值相加,第1张

#!/bin/bash

n=1

for i in `cat 1.txt`do # 循环1.txt

num=`sed -n "${n}p" 2.txt` # 获取2.txt对行的数字

sum=$(($num + $i)) # 两数相加

echo $sum # 打印结果

n=$(($n + 1))

done

int main () {

float a, b, res

char op[] = "+-*/", *p =op

scanf("%f %f", &a, &b)

while (*p) {

switch(*p) {

case '+': res = a+b break

case '-': res = a+b break

case '*': res = a+b break

case '/': if (b)res = a/b break

}

printf("%f %c %f = %f\n", a, *p, b, res)

p++

}

return 0

}

awk '{getline s <"第一个文件"

split(s,array)

for (i=1i<=NFi++) $i=$i-array[5+i]

print }' 第二个文件

结果

9761 98.895 10 1 98.896


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/yw/8987789.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-23
下一篇 2023-04-23

发表评论

登录后才能评论

评论列表(0条)

保存