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)"