使用参数在AIX上求和

时间:2017-01-30 14:30:02

标签: bash shell aix

今天我有一个脚本,里面有一个查询,它执行列名称的SELECT和它的计数。它可以列出超过50多个不同的行。

实施例

BOOK 12
SHELF 2
DESK 3

大纲代码:

[query] | while read unk_mtype_volume ; do

    echo "$unk_mtype_volume"

done

我需要对每一行编号进行SUM,以得到总数。

2 个答案:

答案 0 :(得分:2)

server { server_name www.domain.com www.domain2.com; return 301 $scheme://domain.com$request_uri; } server { server_name domain.com domain2.com; listen 80 default_server ipv6only=on; listen [::]:80; listen 443 ssl; listen [::]:443 ssl; include /etc/nginx/ssl.conf; root /home/domain/public_html; set $no_cache 0; location /admin { set $no_cache 1; } location = /favicon.ico { try_files $uri =204; } location ~* \.(jpe?g|gif|css|png|js|ico|pdf|zip|tar|t?gz|mp3|wav|swf)$ { expires max; } location / { index index.html index.php; try_files $uri $uri/ @handler; #rewrite ^/my-url.html /my-url/ permanent; #rewrite ^/my-url.html http://domain.co.uk/ permanent; expires 7d; } location /shop { try_files $uri /shop/index.php; } location /shop/downloader { # rewrite ^/shop/downloader /shop/downloader/index.php; NO try_files $uri /shop/downloader/index.php; } location ~ ^/(app|includes|media/downloadable|pkginfo|report/config.xml|var)/ { deny all; } location ~ ^/(info.php|var/export/)/ { auth_basic "Restricted Access"; auth_basic_user_file /etc/nginx/htpasswd; } location @handler { rewrite / /index.php; } location ~ .php/ { rewrite ^(.*.php)/ $1 last; } location ~ .php$ { fastcgi_pass unix:/var/run/php/php7.0-fpm.sock; fastcgi_index index.php; fastcgi_split_path_info ^(.+\.php)(/.+)$; fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name; fastcgi_param SCRIPT_NAME $fastcgi_script_name; fastcgi_param PATH_INFO $fastcgi_path_info; fastcgi_param MAGE_RUN_TYPE website; fastcgi_param MAGE_RUN_CODE base; fastcgi_cache phpcache; # The name of the cache key-zone to use fastcgi_cache_valid 200 30m; # What to cache: 'code 200' responses, for half an hour fastcgi_cache_methods GET HEAD; # What to cache: only GET and HEAD requests (ot POST) add_header X-Fastcgi-Cache $upstream_cache_status; # Allow us to see if the cache was HIT, MISS, or BYPASSED inside a browser's Inspector panel fastcgi_cache_bypass $no_cache; # Dont pull from the cache if true fastcgi_no_cache $no_cache; # Dont save to the cache if true include fastcgi_params; } location ~ ([^/]*)sitemap(.*)\.x(m|s)l$ { ## this redirects sitemap.xml to /sitemap_index.xml rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent; ## this makes the XML sitemaps work rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last; rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last; rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last; ## The following lines are optional for the premium extensions ## News SEO rewrite ^/news-sitemap\.xml$ /index.php?sitemap=wpseo_news last; ## Local SEO rewrite ^/locations\.kml$ /index.php?sitemap=wpseo_local_kml last; rewrite ^/geo-sitemap\.xml$ /index.php?sitemap=wpseo_local last; ## Video SEO rewrite ^/video-sitemap\.xsl$ /index.php?xsl=video last; } include /etc/nginx/minify.conf; include /etc/nginx/scripts.conf; location ~ /wp-content/cache/minify.*\.js$ { types {} default_type application/x-javascript; expires modified 31536000s; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; } location ~ /wp-content/cache/minify.*\.css$ { types {} default_type text/css; expires modified 31536000s; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; } location ~ /wp-content/cache/minify.*js\.gzip$ { gzip off; types {} default_type application/x-javascript; expires modified 31536000s; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; add_header Content-Encoding gzip; } location ~ /wp-content/cache/minify.*css\.gzip$ { gzip off; types {} default_type text/css; expires modified 31536000s; add_header Vary "Accept-Encoding"; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; add_header Content-Encoding gzip; } location ~ \.(css|htc|less|js|js2|js3|js4)$ { expires 31536000s; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; } location ~ \.(htm|rtf|rtx|svg|svgz|xsd|xsl|xml)$ { expires 3600s; add_header Pragma "public"; add_header Cache-Control "max-age=3600, public"; } location ~ \.(asf|asx|wax|wmv|wmx|avi|bmp|class|divx|doc|docx|eot|exe|gif|gz|gzip|ico|jpg|jpeg|jpe|json|mdb|mid|midi|mov|qt|mp3|m4a|mp4|m4v|mpeg|mpg|mpe|mpp|otf|odb|odc|odf|odg|odp|ods|odt|ogg|pdf|png|pot|pps|ppt|pptx|ra|ram|svg|svgz|swf|tar|tif|tiff|ttf|ttc|wav|wma|wri|woff|xla|xls|xlsx|xlt|xlw|zip)$ { expires 31536000s; add_header Pragma "public"; add_header Cache-Control "max-age=31536000, public"; } rewrite ^/wp-content/cache/minify.*/w3tc_rewrite_test$ /wp-content/plugins/w3-total-cache/pub/minify.php?w3tc_rewrite_test=1 last; set $w3tc_enc ""; if ($http_accept_encoding ~ gzip) { set $w3tc_enc .gzip; } if (-f $request_filename$w3tc_enc) { rewrite (.*) $1$w3tc_enc break; } rewrite ^/wp-content/cache/minify/(.+/[X]+\.css)$ /wp-content/plugins/w3-total-cache/pub/minify.php?test_file=$1 last; rewrite ^/wp-content/cache/minify/(.+\.(css|js))$ /wp-content/plugins/w3-total-cache/pub/minify.php?file=$1 last; } 这是一项简单的工作,不需要在文件/输入行上进行昂贵的迭代。只需添加第二个字段,最后打印值:

awk

如果输入来自STDIN:

awk '{sum+=$2} END{print sum}' file.txt

示例:

... | awk '{sum+=$2} END{print sum}'

答案 1 :(得分:0)

您可以(我会)使用awk来完成工作 - heemaylanswer中显示。您也可以使用纯Bash:

sum=0
while read location number
do
    sum=$(($sum + $number))
done
echo "Total: $sum"

请注意,如果任何“位置”包含多个单词,则此内容很脆弱。您可以在awk中比Bash更轻松地编写代码。