AWK 實例
时间:2007-09-24 来源:prefect
Eg 1
111 2 11111
123 1 13341
122 2 11322
.......
切割后:
根据$2分类..
文件1.
111 1 11111
122 1 11342
文件2.
111 2 11111
122 2 11111
123 2 11111
文件3.........
我自己贴吧
for i in `ls $path`
for k in 1 2 3 4 5 6 7 8
do
awk { if ($2=='"$k"') print $0}' $path/$i >> $path/$k.DAT
done
done
或:
awk '{if ($2==1)print $0}' file >file1
awk '{if ($2==2)print $0}' file >file2
.......
Eg 2
cat file
AAA2AA00111111000.00 200507
BBB2BB0012222500.00 200506
CCC6AA0023333200.00 200508
DDD5BB00344443000.00 200509
EEE6DD00355556000.00 200510
处理后:
awk '{a1=substr($1,1,3);a2=substr($1,4,3);a3=substr($1,7,3);a4=substr($1,10,4);a5=substr($1,14);print a1,a2,a3,a4,a5,$2}' file
AAA 2AA 001 1111 1000.00 200507
BBB 2BB 001 2222 500.00 200506
CCC 6AA 002 3333 200.00 200508
DDD 5BB 003 4444 3000.00 200509
EEE 6DD 003 5555 6000.00 200510