linux求和
A. linux shell两个文件数值相加
#!/bin/bash
n=1
foriin`cat1.txt`;do#循环1.txt
num=`sed-n"${n}p"2.txt`#获取2.txt对行的数字
sum=$(($num+$i))#两数相加
echo$sum#打印结果
n=$(($n+1))
done
B. LINUX:编写一个shell脚本,并利用函数实现数列求和运算
#!/bin/bash
sum=0
if[$#-ne2]
then
echo"Pleaseinputtwonumbers!"
elif[$1-gt$2]
then
echo"."
else
foriin$(seq$1$2)
do
sum=`expr$sum+$i`
done
echo""$1~$2"sumis$sum"
fi
#执行结果
#[root@localhostopt]#./b.sh36
#"3~6"sumis18
#[root@localhostopt]#./b.sh3
#Pleaseinputtwonumbers!
#[root@localhostopt]#./b.sh356
#Pleaseinputtwonumbers!
#[root@localhostopt]#./b.sh32
#.
#[root@localhostopt]#./b.sh325
#"3~25"sumis322
C. linux中如何用shell求解一列数字的和
awk'{count[$1]+=$2}
END{for(keyincount)
if(count[key]>maxkey)
{
result=key
}
printresult
}'
D. linux里一行数字间的空格被加号替换了以后怎么求和想了很久没想出来。
str="123456"
echo"${str///+}"|bc
用 bc 求和啊
有问题可以追问
E. linux 对某个文件夹下面的文件进行统计(求和)
tar -tvf file.tar 查看file.tar里的文件
tar -tvf file.tar | wc -l ### file.tar 里的文件总和
F. 如何用Linux shell语句对文本内容求和,
有两条思路。用awk抽取第一第二行不想等的值,shell script去处理比较,最后生成一个总的,或者三列。四列各输出到一个文件。然后去求和。另一条思路是完全用awk脚本去做。awk脚本和c一样的语法模式。
G. linux下有没有对一列数字进行求和的命令
额,目测没有这样的程序。
不过可以自己写一个c的实现
#include<stdio.h>
#include<stdlib.h>
intmain(intargc,char*argv[])
{
inti,res=0;
for(i=1;i<argc;i++)
res+=atoi(argv[i]);
printf("%d",res);
return0;
}
匆忙写的,可能有问题,见谅。
编译后用 ./a.out 1 2 3 4 5...... numberN调用即可。
H. LINUX awk 语句 awk ' { SUM += $1 } END { print SUM }'请问这个要怎么理解,需详细
1、首先awk截取指定域,在日志的处理和监控中,经常会截取指定的字符来进行后续处理。如:从df -h命令中提取/目录所占百分比(监控经常会用到)。
I. linux能否用bc求和uniq的数据
用awk累加:
last|grep[a-zA-Z]|cut-d''-f1|sort|uniq-c|awk'{sum+=$1}END{printsum}'
J. 求编写linux shell 程序求和使用for语句创建一个shell程序,其功能是1+2+3+…+n.请高手们帮下忙!要可...
#!/bin/bash
echo "Input n:"
read n
s=0
for (( i=0;i<n+1;i=i+1 ))
do
let s=$s+$i
done
echo "1+2+...+n = $s(n=$n)"