shell 求总分
求总分并且输出:
文件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 求总分的更多相关文章
- 用shell求两个文件的差集
假设有两个文件a.file和b.file,分别代表集合A和集合B. a.file的内容如下: abcde b.file的内容如下: cdefg 可以用grep命令 grep命令是常用来搜索文本内容的, ...
- shell 求模
$ expr % $ let i=% $ echo $i $ echo % | bc $ ((i=%)) $ echo $i
- shell 求幂
$ let i=** $ echo $i $ ((i=**)) $ echo $i $ echo "5^2" | bc
- shell 求数组的平均值,求和,最大值,最小值
test.sh #!/bin/bash arr=( ) let min=${arr[]} let max=${min} sum= ;i<${#arr[*]};i++)) do [[ ${min} ...
- 最全的linux命令大全,shell运维手册
shell实例手册 0 说明{ 手册制作: 雪松} 1 文件{ ls -rtl # 按时间倒叙列出所有目录和文件 ll -rt touch file ...
- (转)shell实例手册
原文地址:http://hi.baidu.com/quanzhou722/item/f4a4f3c9eb37f02d46d5c0d9 实在是太好的资料了,不得不转 shell实例手册 0说明{ 手册制 ...
- shell 实例
转载自:https://github.com/liquanzhou/ops_doc 这里只作为笔记使用,不做他用 shell实例手册 0 说明{ 手册制作: 雪松 更新日期: 2018-09-1 ...
- shell脚本之特殊符号总结性梳理
# 井号 (comments) 这几乎是个满场都有的符号#!/bin/bash 井号也常出现在一行的开头,或者位于完整指令之后,这类情况表示符号后面的是注解文字,不会被执行. # This line ...
- [Erlang30]Erlang shell是如何工作的?
一些关于Erlang启动进程的分析:希望你会喜欢. 原英文地址:http://ferd.ca/repl-a-bit-more-and-less-than-that.html 研究Erlang shel ...
随机推荐
- JQuery select控件的相关操作
JQuery获取和设置Select选项方法汇总如下: 获取select 先看看下面代码: $("#select_id").change(function(){//code...}) ...
- 《C和指针》章节后编程练习解答参考——6.1
<C和指针>——6.1 6.1 题目: 编写一个函数,在一个字符串中进行搜索,查找另一子字符串中出现的字符. 函数原型如下: char *find_char(char const *sou ...
- 使用date命令,进行时间戳和日期时间的互转
首先是知道时间转成时间戳 date -d "2014-01-16 12:30:11" +%s - :: - :: 其次是知道时间戳,想要知道当时的时间 date -d '1970- ...
- Kent Beck揭秘Facebook开发部署流程
http://www.infoq.com/cn/news/2013/10/facebook-development-deployment Facebook是世界上最大的社交网站,有超过10亿用户每月至 ...
- 45 Useful JavaScript Tips, Tricks and Best Practices(有用的JavaScript技巧,技巧和最佳实践)
As you know, JavaScript is the number one programming language in the world, the language of the web ...
- cf D. On Sum of Fractions
http://codeforces.com/problemset/problem/397/D 题意:v(n) 表示小于等于n的最大素数,u(n)表示比n的大的第一个素数,然后求出: 思路:把分数拆分成 ...
- Tautology
WFF 'N PROOF is a logic game played with dice. Each die has six faces representing some subset of th ...
- 通过CreateOleObject控制IE
//第二种方法可以有更多控制procedure TForm1.Button1Click(Sender: TObject);procedure OpenInIE(aURL: string);//need ...
- Android 批量上传sd卡图片
最近手头上需要批量上传一些保存到SD卡图片由于简单,过于忘记,写在博客中吧!同时也希望能帮到大家! 一 . 以下是一个Service类 package cn.com.service; import j ...
- 根据body的内容 查找h2标签的@class="subtitle"的值
<pre name="code" class="html"><body class="api jquery listing" ...