awk 练习2

em@em-laptop:~/Desktop/unix/chap06/Ex_6.055-6.089$ cat lab4.data
Mike Harrington:(510) 548-1278:250:100:175
Christian Dobbins:(408) 538-2358:155:90:201
Susan Dalsass:(206) 654-6279:250:60:50
Archie McNichol:(206) 548-1348:250:100:175
Jody Savage:(206) 548-1278:15:188:150
Guy Quigley:(916) 343-6410:250:100:175
Dan Savage:(406) 298-7744:450:300:275
Nancy McNeil:(206) 548-1278:250:80:75
John Goldenrod:(916) 348-4278:250:100:175
Chet Main:(510) 548-5258:50:95:135
Tom Savage:(408) 926-3456:250:168:200
Elizabeth Stachelin:(916) 440-1763:175:75:300

 

1. 打印在第二个月捐款超过100元的人的姓名。

2. 打印在最后一个月捐款少于85元的人的姓名和电话号码。

3. 打印在第一个月捐款额在75元到165元之间的人。

4. 打印在这三个月捐款总额超过800元的人。

5. 打印月均捐款额大于200元的人的姓名和电话号码 .

6. 打印不在916区的人的姓 .

7. 打印每条记录,并在记录前加上其记录号

8. 打印每个人的姓名和捐款总额

9. 把Chet第二个月的捐款额加上10

10. 把Nancy McNeil的名字改成Louise McInnes

 

1.em@em-laptop:~/$ awk -F: ' $4 > 100 {print $1}' lab4.data
Jody Savage
Dan Savage
Tom Savage

 

2.em@em-laptop:~/D$ awk -F: '$5 < 85 {print $1,$2}' lab4.data

结果有些不理想....

 

3.em@em-laptop:~/$ awk -F: '$3 > 75 && $3 < 165 {print $1}' lab4.data
Christian Dobbins

 

4.em@em-laptop:~/$ awk -F: '($3+$4+$5) < 800 {print $1}' lab4.data
Mike Harrington
Christian Dobbins
Susan Dalsass
Archie McNichol
Jody Savage
Guy Quigley
Nancy McNeil
John Goldenrod
Chet Main
Tom Savage
Elizabeth Stachelin

 

5.em@em-laptop:~/$ awk -F: '(($3+$4+$5)/3) > 200 {print $1,$2}' lab4.data
Dan Savage (406) 298-7744
Tom Savage (408) 926-3456

 

6.em@em-laptop:~/$ awk -F '[ :]' '$3 !~ /916/{print $1,$2}' lab4.data
Mike Harrington
Christian Dobbins
Susan Dalsass
Archie McNichol
Jody Savage
Dan Savage
Nancy McNeil
Chet Main
Tom Savage

 

7.em@em-laptop:~/$ awk  '{print NR,$0}' lab4.data
1 Mike Harrington:(510) 548-1278:250:100:175
2 Christian Dobbins:(408) 538-2358:155:90:201
3 Susan Dalsass:(206) 654-6279:250:60:50
4 Archie McNichol:(206) 548-1348:250:100:175
5 Jody Savage:(206) 548-1278:15:188:150
6 Guy Quigley:(916) 343-6410:250:100:175
7 Dan Savage:(406) 298-7744:450:300:275
8 Nancy McNeil:(206) 548-1278:250:80:75
9 John Goldenrod:(916) 348-4278:250:100:175
10 Chet Main:(510) 548-5258:50:95:135
11 Tom Savage:(408) 926-3456:250:168:200
12 Elizabeth Stachelin:(916) 440-1763:175:75:300

 

8.em@em-laptop:~/$ awk -F: '$6 = ($3+$4+$5) {print $1,$6}' lab4.data
Mike Harrington 525
Christian Dobbins 446
Susan Dalsass 360
Archie McNichol 525
Jody Savage 353
Guy Quigley 525
Dan Savage 1025
Nancy McNeil 405
John Goldenrod 525
Chet Main 280
Tom Savage 618
Elizabeth Stachelin 550

 

9.em@em-laptop:~/$ awk -F: '/^Chet/{print $1,$4+10}' lab4.data
Chet Main 105

 

10.em@em-laptop:~/$ awk -F: '$1 == "Nancy McNeil"{ $1 = "Louise McInnes"; print}' lab4.data
Louise McInnes (206) 548-1278 250 80 75

你可能感兴趣的:(unix,F#,360)