shell脚本学习每日一句(2)

5月21号 晚上8点更新

employee文件中记录了工号和姓名

employee.txt:
100 Jason Smith
200 John Doe
300 Sanjay Gupta
400 Ashok Sharma
bonus文件中记录工号和工资
bonus.txt:
100 $5,000
200 $500
300 $3,000
400 $1,250
要求把两个文件合并并输出如下
处理结果:
400 ashok sharma $1,250
100 jason smith $5,000
200 john doe $500

300 sanjay gupta $3,000

[root@fsailing1 shell]# vim employee.txt [root@fsailing1 shell]# vim bonus.txt [root@fsailing1 shell]# paste employee.txt bonus.txt 100 Jason Smith 100 $5,000 200 John Doe 200 $500 300 Sanjay Gupta 300 $3,000 400 Ashok Sharma 400 $1,250 [root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1 $2 $3 $ 5}' 100JasonSmith$5,000 200JohnDoe$500 300SanjayGupta$3,000 400AshokSharma$1,250[root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1,$2,$3,$5}' 100 Jason Smith $5,000 200 John Doe $500 300 Sanjay Gupta $3,000 400 Ashok Sharma $1,250[root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1 , $2 , $3 , $5}'|tr '[:lower:]' '[:upper:]' 100 JASON SMITH $5,000 200 JOHN DOE $500 300 SANJAY GUPTA $3,000 400 ASHOK SHARMA $1,250 [root@fsailing1 shell]# paste employee.txt bonus.txt |awk '{print $1 , $2 , $3 , $5}'|tr '[:upper:]' '[:lower:]'|sort -k 2 400 ashok sharma $1,250 100 jason smith $5,000 200 john doe $500 300 sanjay gupta $3,000

5月22号 下午2点

文件格式如下:

100
a 100
b -50
c -20
d -30
要求输出结果为:
100
a 100
200
b -50
150
c -20
130
d -30

100

[root@fsailing1 shell]# awk '{print $0;print $1}' test.txt 100 100 a 100 a b -50 b c -20 c d -30 d [root@fsailing1 shell]# awk 'NR==1{sum=$1;print $0}' test.txt NR表示awk读到的文件行数。 100 [root@fsailing1 shell]# awk 'NR==1{sum=$1;print $0} NR!=1{print $0;print sum+=$2}' test.txt 100 a 100 200 b -50 150 c -20 130 d -30 100





评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值