(对一列数字求和)
在日常工作当中需要对文本过滤出来的数字进行求和运算,例如想统计一个MySQL分区表现在有多大
# ls -lsh AdPlateform#P#p*.ibd  |grep G
2.6G -rw-rw---- 1 mysql mysql 2.6G Mar  4 01:05 AdPlateform#P#p20200304.ibd
2.9G -rw-rw---- 1 mysql mysql 2.9G Mar  5 01:12 AdPlateform#P#p20200305.ibd
# ls -lsh AdPlateform#P#p*.ibd  |grep G|awk   '{sum+=$6} END{print "sum="sum}'
sum=5.5
 
 
 
(对一行数字求和)
在日常工作当中需要对一行文本进行求和运算
# cat 1.txt
1 2 3 4 5 6 7 8 9 10
# cat 1.txt |awk '{for(i=1;i<=NF;i++) sum+=$i} END{print "sum="sum}'  
sum=55
 
 
(行转列)
# cat 1.txt
1 2 3 4 5 6 7 8 9 10
# awk '{for(i=1;i<=NF;i++)a[NR,i]=$i}END{for(j=1;j<=NF;j++)for(k=1;k<=NR;k++)printf k==NR?a[k,j] RS:a[k,j] FS}' 1.txt
1
2
3
4
5
6
7
8
9
10
 
 
(列转行)
# cat 2.txt
1
2
3
4
5
6
7
8
9
10
# cat 2.txt |tr "\n" ","|sed -e 's/,$/\n/'|tr "," " "
1 2 3 4 5 6 7 8 9 10
 
(取出ip字段的前几列)
# echo "10.10.33.161.62342" |awk -F'.' {'print $1,$2,$3,$4'}|tr " " "."
10.10.33.161
 

Linux Shell 统计一(行\列)数值的总和及行、列转换的更多相关文章

  1. linux shell 统计当前目录下的文件个数

    shell 统计当前目录下文件个数,使用管道组合命令: ls -1 | wc -l 解释: ls -1 表示一行一个列出文件名. wc -l 表示打印统计的行数. 两个命令通过管道连在一起表示打印列出 ...

  2. Linux Shell: 统计系统中占用Swap 的程序PID和占用大小

    #!/bin/bash  SUM=0 OVERALL=0 for DIR in `find /proc/ -maxdepth 1 -type d -regex "^/proc/[0-9]+& ...

  3. Linux shell脚本基础学习详细介绍(完整版)二

    详细介绍Linux shell脚本基础学习(五) Linux shell脚本基础前面我们在介绍Linux shell脚本的控制流程时,还有一部分内容没讲就是有关here document的内容这里继续 ...

  4. linux shell脚本查找重复行/查找非重复行/去除重复行/重复行统计

    转自:http://blog.sina.com.cn/s/blog_6797a6700101pdm7.html 去除重复行 sort file |uniq 查找非重复行 sort file |uniq ...

  5. linux下shell统计文件目录下所有代码行数

    功能,统计某一目录下所有文件代码行数: 例如统计某一目录下所有.c结尾的文件代码行数:find . -name "*.c"|xargs cat|grep -v ^$|wc -l ^ ...

  6. Linux shell 脚本攻略之统计文件的行数、单词数和字符数

    摘自:<Linux shell 脚本攻略>

  7. Linux显示文件前几行、拷贝文件前几行、删除文件前几列

    [一]显示文件前几行 ll -lrth:按照更改时间倒序排列,最新文件在下边 ll -lrSh:按照文件大小倒序排列,最大文件在下边 grep --color :高亮查询关键字 grep -A 10 ...

  8. [转帖]linux Shell sort按照指定列排序

    linux Shell sort按照指定列排序 https://blog.csdn.net/weixin_38308151/article/details/80760133 kubectl get p ...

  9. shell 统计某个文件的行数命令

    语法:wc [选项] 文件- 说明:该命令统计给定文件中的字节数.字数.行数.如果没有给出文件名,则从标准输入读取.wc同时也给出所有指定文件的总统计数.字是由空格字符区分开的最大字符串. 该命令各选 ...

随机推荐

  1. WIN10修改应用的默认打开方式

    如图所示: 选中想要替换成为的应用程序, 在其中勾选想设默认应用的文件类型即可.

  2. CSS Grid & Flex poster PDF 海报定制

    CSS Grid & Flex poster PDF 海报定制 CSS 手工实现 导出 SVG / PNG 导出 PDF 打印,定制海报 refs https://css-tricks.com ...

  3. TensorFlow & Machine Learning

    TensorFlow & Machine Learning TensorFlow 实战 传统方式 规则 + 数据集 => 答案 无监督学习 机器学习 神经元网络 答案 + 数据集 =&g ...

  4. JavaScript interview Question - Create a Array with two papameters without using loop!

    JavaScript interview Question - Create a Array with two papameters without using loop! JavaScript - ...

  5. How to enable HTTPS for local development in macOS using Chrome

    How to enable HTTPS for local development in macOS using Chrome HTTPS, macOS, Chrome local HTTPS htt ...

  6. 如何使用 js 实现一个树组件

    如何使用 js 实现一个树组件 tree component const arr = [ { id: 1, value: 1, level: 1, parentId: 0, }, { id: 2, v ...

  7. LeetCode & linked list bug

    LeetCode & linked list bug add-two-numbers shit test /** * Definition for singly-linked list. * ...

  8. code magic

    code magic CI/CD for mobile app projects https://codemagic.io https://codemagic.io/apps flutter http ...

  9. Inspect Network Activity In Chrome DevTools

    Inspect Network Activity In Chrome DevTools https://developers.google.com/web/tools/chrome-devtools/ ...

  10. nasm 函数返回一个数组 x86

    getArguments.asm: extern VirtualAlloc section .text global dllmain export getArguments dllmain: mov ...