当前位置: 首页 > shell > 正文

a script of awk array – just mark

Just mark it. 🙂

#!/bin/sh
awk -F”_t_7_Y_” ‘{if($1==1) {printf $2; for(i=3;i<=NF;i++) if(i==NF) print $i;else printf $i}}’ temp1  > 1.txt
awk -F”_t_7_Y_” ‘{if($1==2) if($2 in S22){S22[$2]=$2;S23[$2]=$3″ “S23[$2];N2[$2]++}else {S22[$2]=$2;S23[$2]=$3;N2[$2]=1;} if($1==3) if($2 in S32){S32[$2]=$2;S33[$2]=$3″ “S33[$2];N3[$2]++}else {S32[$2]=$2;S33[$2]=$3;N3[$2]=1;} if($1==4) if($2 in S42){S42[$2]=$2;S43[$2]=$3″ “S43[$2];N4[$2]++}else {S42[$2]=$2;S43[$2]=$3;N4[$2]=1;} }END{for(i in S22) print S22[i],N2[i],S23[i]>>”2.txt”;for(i in S32) print S32[i],N3[i],S33[i]>>”3.txt”; for(i in S42) print S42[i],N4[i],S43[i]>>”4.txt”;}‘ temp1

awk ‘NR==FNR {for(i=2;i<=NF;i++) S[$1]=S[$1]” “$i;}NR>FNR{print $0” “S[$1]}’ 2.txt 1.txt > t1.txt
awk ‘NR==FNR {for(i=2;i<=NF;i++) S[$1]=S[$1]” “$i;}NR>FNR{print $0” “S[$1]}’ 3.txt t1.txt > t2.txt
awk ‘NR==FNR {for(i=2;i<=NF;i++) S[$1]=S[$1]” “$i;}NR>FNR{print $0” “S[$1]}’ 4.txt t2.txt > final.txt

本文固定链接: http://2hei.net/a_script_of_awk_array.html | 2hei's site

该日志由 2hei 于2010年09月06日发表在 shell 分类下,
原创文章转载请注明: a script of awk array – just mark | 2hei's site
关键字:

报歉!评论已关闭.