awk 是unix ***能最强的过滤器。
awk [-F 分隔符] ' -f 程序文件 [文件1.....文件n]
实例:
1 .
- cat first |awk '{sum = sum+ $1}; END {print sum}'
打印第二字段
2.
- awk '{sum = sum+ $1}; END {print sum}' first
输出第一列的和
或者
- cat first |awk '{sum = sum+ $1}; END {print sum}'
awk
- # $@ all the arguments
-
2 #delete rows that contains %
-
3
-
4 sed '/\%/d' $@ >fv1
-
5 sed '1,1 d' fv1 >f1
-
6 sort -n -k 1 -k 2 f1>fv1.0
-
7 awk '{print $1}' fv1.0 >fv1.1
-
8 awk '
-
9 BEGIN {pre=1;
-
10 row=1;
-
11 k=1;
-
12 row_start[0]=1;
-
13 }
-
14 {
-
15 {
-
16 if(pre!=$1)
-
17 {
-
18 row_start[row]=k;
-
19 row=row+1;
-
20 pre=$1
-
21 }
-
22 k=k+1;
-
23 next
-
24 }
-
25
-
26 }
-
27
-
28 END{
-
29 row_start[row]=k;
-
30 for(j=0;j<=row;j++)
-
31 printf "%d\n", row_start[j]
-
32 }' fv1.1 >fv1.2
-
33
-
34 awk '{print $2 }' fv1.0 >>fv1.2
-
35 awk '{print $3 }' fv1.0 >>fv1.2
-
36
阅读(579) | 评论(0) | 转发(0) |