The UNIX and Linux Forums  


Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com




View Single Post in the UNIX and Linux Forums - Click on the Thread or Permalink to View Entire Thread -->
  #1 (permalink)  
Old 04-09-2008
deepakgang deepakgang is offline
Registered User
  
 

Join Date: Oct 2007
Posts: 38
Split file into multiple files depending upon first 4 digits

Hi All,

I have a file like below:

1016D"ddd","343","1299"
1016D"ddd","3564","1299"
1016D"ddd","3297","1393"
1016D"ddd","32989","1527"
1016D"ddd","346498","1652"
2312D"ddd","3269","1652"
2312D"ddd","328","1652"
2312D"ddd","2224","2100"
3444D"ddd","252","2100"
3444D"ddd","2619","2100"


I need to split this big file (will contain lot of records like above) into multiple files depending upon the first 4 digits. The output files will be like:

filename.1016.dat

1016D"ddd","343","1299"
1016D"ddd","3564","1299"
1016D"ddd","3297","1393"
1016D"ddd","32989","1527"
1016D"ddd","346498","1652"

filename.2312.dat

2312D"ddd","3269","1652"
2312D"ddd","328","1652"
2312D"ddd","2224","2100"

filename.3444.dat

3444D"ddd","252","2100"
3444D"ddd","2619","2100"


I searched for some examples but they all are done using awk.. and as there is no field separator here I cant use awk..

Please help.

Thanks
D