divide the file into multiple files based on the city name

Hi,

I have a file abc.dat. It contains the fileds of empid, empname, empcity. each city contains 10 records. i want to create the city file and pass the same city records into the file. I don't know the city names.

In unix using awk command how can we do?

abc.dat:

1 john delhi
2 smith pune
3 chandra bangalore
4 mohan delhi
5 singh delhi
6 goud pune
7 somnath bangalore
etc..

output:

delhi.dat
1 john delhi
4 mohan delhi
5 singh delhi

pune.dat
2 smith pune
6 goud pune

bangalore.dat
3 chandra bangalore
7 somnath bangalore

Thanks in advance

 
awk '{a=$3".dat";printf("%s\n",$0) >> a}' abc.dat

thanks. its working.