Shell脚本,用于将行相乘并将总和相加
但我不知道为什么最后的4096会出现在我的输出中 然后我还需要删除(字节)并只打印值,所以我使用了下面的语法Shell脚本,用于将行相乘并将总和相加,shell,Shell,但我不知道为什么最后的4096会出现在我的输出中 然后我还需要删除(字节)并只打印值,所以我使用了下面的语法 Thanks all for the inputs but now i landed up in another problem . This is my Orginal syntax db2 list tablespaces show detail | grep -e " Free pages" -e " Page size" Free pages
Thanks all for the inputs but now i landed up in another problem .
This is my Orginal syntax
db2 list tablespaces show detail | grep -e " Free pages" -e " Page size"
Free pages = Not applicable
Page size (bytes) = 4096
Free pages = Not applicable
Page size (bytes) = 4096
Free pages = Not applicable
Page size (bytes) = 4096
Free pages = 36960
Page size (bytes) = 32768
Free pages = 40800
Page size (bytes) = 16384
Free pages = 22656
Page size (bytes) = 4096
Free pages = Not applicable
Page size (bytes) = 4096
Now if i see Not applicable then i should remove Not applicable line and as well as the proceeding line for that i used the below syntax
db2 list tablespaces show detail | grep -e " Free pages" -e " Page size" | awk '/Not/{getline;next} 1'
Free pages = 36960
Page size (bytes) = 32768
Free pages = 40800
Page size (bytes) = 16384
Free pages = 22656
Page size (bytes) = 4096
36960
32768
40800
16384
22656
4096
我忘了提到关于我的第一篇帖子(我的问题是我想将第1行乘以第2行,然后将第3行乘以第4行,将第5行乘以第6行,直到输出结束,最后将整个总和相加)
如下
36960*32
40800 * 16
然后继续
由此我需要GB中的值除以1024,再除以1024,因为原始值是KB
in the second line , fourth line and sixth line i need to take only the first 2 charchater and then multiply
对于bash
shell脚本
:
I know i am asking too much but can some one help ??
Waiting for some reply .. Thanks
然后运行:
#!/bin/bash
TOTAL=0
while read A && read B; do
(( TOTAL += A * B ))"
done
echo "Total: $(( TOTAL / 1024 / 1024 )) GB"
bash script.sh
如果您希望它能够跨多种类型的shell使用,那么这个概念应该很容易转换。请考虑命令<代码> BC/<代码>和其他类似的工具。
#!/bin/bash
TOTAL=0
while read A && read B; do
(( TOTAL += A * B ))"
done
echo "Total: $(( TOTAL / 1024 / 1024 )) GB"
bash script.sh < input_file