- 论坛徽章:
- 0
|
% cat datafile
northwest NW Joel Craig 3.0 .98 3 4
western WE Sharon Kelly 5.3 .97 5 23
southwest SW Chris Foster 2.7 .8 2 18
southern SO May Chin 5.1 .95 4 15
southeast SE Derek Johnson 4.0 .7 4 17
eastern EA Susan Beal 4.4 .84 5 20
northeast NE TJ Nichols 5.1 .94 3 13
north NO Val Shultz 4.5 .89 5 9
central CT Sheri Watson 5.7 .94 5 13
% cat awk.sc6
# Awk and the special for loop
{region[$1]++} # The index is the first field of each record
END{for(item in region){
print region[item], item
}
}
% awk -f awk.sc6 datafile
1 central
1 northwest
1 western
1 southeast
1 north
1 southern
1 northeast
1 southwest
1 eastern
执行awk脚本后,输出第一排是central,第二个变成northwest,请教大家,从上到下,按什么顺序输出的,还是随机输出的? |
|