求总分并且输出:
文件a.txt
学号 姓名 性别 年龄
张三 男
赵四 男
李丽 女
文件b.txt
学号 语文 数学 英语 方法1:
#!/bin/sh
paste a.txt b.txt ccc.txt
cat ccc.txt |awk 'NR==1{ printf "%10s %10s %10s %10s %10s %10s %10s\n",$1,$2,$3,$6,$7,$8,"总分"}NR>=2{{zongfen=$6+$7+$8}{printf "%10s %10s %10s %10s %10s %10s %10s\n",$1,$2,$3,$6,$7,$8,zongfen}}' 方法2:
#!/bin/sh
for i in `cat aa.txt |awk '{ print $1}'`
do
a=`grep $i aa.txt |awk '{print $1}'`
b=`grep $i aa.txt |awk '{print $2}'`
c=`grep $i aa.txt |awk '{print $3}'`
d=`grep $i aa.txt |awk '{print $4}'`
e=`grep $i bb.txt |awk '{print $2}'`
f=`grep $i bb.txt |awk '{print $3}'`
g=`grep $i bb.txt |awk '{print $4}'`
if [ $a != "学号" ]
then
sum=`grep $i bb.txt |awk '{$5=$2+$3+$4;print $5 }'`
echo $a"\t" $b"\t" $c"\t" $d"\t" "$e\t" "$f\t" $g"\t" $sum"\t"
else
echo $a"\t" $b"\t" $c"\t" $d"\t" $e"\t" $f"\t" $g"\t" "总分""\t"
fi
done

shell 求总分的更多相关文章

  1. 用shell求两个文件的差集

    假设有两个文件a.file和b.file,分别代表集合A和集合B. a.file的内容如下: abcde b.file的内容如下: cdefg 可以用grep命令 grep命令是常用来搜索文本内容的, ...

  2. shell 求模

    $ expr % $ let i=% $ echo $i $ echo % | bc $ ((i=%)) $ echo $i

  3. shell 求幂

    $ let i=** $ echo $i $ ((i=**)) $ echo $i $ echo "5^2" | bc

  4. shell 求数组的平均值,求和,最大值,最小值

    test.sh #!/bin/bash arr=( ) let min=${arr[]} let max=${min} sum= ;i<${#arr[*]};i++)) do [[ ${min} ...

  5. 最全的linux命令大全,shell运维手册

    shell实例手册 0 说明{ 手册制作: 雪松} 1 文件{        ls -rtl                 # 按时间倒叙列出所有目录和文件 ll -rt    touch file ...

  6. (转)shell实例手册

    原文地址:http://hi.baidu.com/quanzhou722/item/f4a4f3c9eb37f02d46d5c0d9 实在是太好的资料了,不得不转 shell实例手册 0说明{ 手册制 ...

  7. shell 实例

    转载自:https://github.com/liquanzhou/ops_doc    这里只作为笔记使用,不做他用 shell实例手册 0 说明{ 手册制作: 雪松 更新日期: 2018-09-1 ...

  8. shell脚本之特殊符号总结性梳理

    # 井号 (comments) 这几乎是个满场都有的符号#!/bin/bash 井号也常出现在一行的开头,或者位于完整指令之后,这类情况表示符号后面的是注解文字,不会被执行. # This line ...

  9. [Erlang30]Erlang shell是如何工作的?

    一些关于Erlang启动进程的分析:希望你会喜欢. 原英文地址:http://ferd.ca/repl-a-bit-more-and-less-than-that.html 研究Erlang shel ...

随机推荐

  1. google zxing 二维码扫描(android client分析)

    一.总体架构 二.架构分析 1. com.google.zxing.client.android AmbientLightManager 环境光线管理 Detects ambient light an ...

  2. Expression Trees

    Expression Trees 只是想简单说下表达式树 - Expression Trees 目录 简介 Lambda 表达式创建表达式树 API 创建表达式树 解析表达式树 表达式树的永久性 编译 ...

  3. Mysql 授权访问

    ' WITH GRANT OPTION; FLUSH PRIVILEGES; 这就是设置一个 urser:root pwd: 账号,该账号可以在任何机器,同时访问服务器

  4. jquery的几个小例子

    <%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding= ...

  5. Vessels

    Codeforces Round #218 (Div. 2) D:http://codeforces.com/problemset/problem/371/D 题意:就是有一些盘子,盘子里可以装水,这 ...

  6. 自制SCVMM 模板成功

    其实,如果通过SCVMM 的PS命令来创建虚拟机的话,模板的意义也不是特别大. 其它的PROFILE和硬件配置都会被替换掉的. ~~~~~~~~~~~~~~~ Windows模版 一. 准备OS的VH ...

  7. 【原生态跨平台:ASP.NET Core 1.0(非Mono)在 Ubuntu 14.04 服务器上一对一的配置实现-篇幅1】

    鸡冻人心的2016,微软高产年. build 2016后 各种干货层出不穷. 1 Win10 集成了bash  ,实现了纳德拉的成诺,Microsoft Love Linux!!! 2 跨平台  ,收 ...

  8. Linux2.6内核--内存管理(2)--区

    由于硬件的限制,内核不能对所有的页一视同仁.有些页位于内存中的特定物理地址上,所以,不能将其用于一些特别的任务.(关于内存分页机制可以查看:http://blog.csdn.net/dlutbruce ...

  9. 后缀自动机(SAM) :SPOJ LCS - Longest Common Substring

    LCS - Longest Common Substring no tags  A string is finite sequence of characters over a non-empty f ...

  10. 【最大流】BAPC2014 A Avoiding the Apocalypse (Codeforces GYM 100526)

    题目链接: http://codeforces.com/gym/100526 http://acm.hunnu.edu.cn/online/?action=problem&type=show& ...