How to split file into multiple files using awk based on 1 field in the file?

Good day all

I need some helps,

say that I have data like below, each field separated by a tab

DATE            NAME    ADDRESS
15/7/2012     LX         a.b.c
15/7/2012     LX1        a.b.c
16/7/2012     AB         a.b.c
16/7/2012     AB2        a.b.c
15/7/2012     LX2        a.b.c
15/7/2012     LX3         a.b.c
17/6/2012     CD         a.b.c

How can split this file into

Option 1: 3 daily files

15/7/2012
16/7/2012
17/6/2012

Option 2: 2 monthly files

june2012
july2012

Hi alexyyw,

Welcome to the forum.

You could try these options.

For option1:

awk '{split($1,a,"/"); x="_"; print > a[1] x a[2] x a[3]}' file

For option2:

awk '{split($1,a,"/"); x="_"; print > a[2] x a[3]}' file

Please use code-tags next time.

Hi alexyyw,

clx was faster, but here you have other way to have the result :

Option 1 :

awk '$1 ~ /.*\/.*\/..../ { split($1,a,"/"); print >a[1]"_"a[2]"_"a[3]; }' alexyyw.inputfile

Option 2 :

awk '$1 ~ /.*\/.*\/..../ { split($1,a,"/"); print >strftime("%B%Y",mktime(sprintf("%04d %02d %02d 00 00 00",a[3],a[2],a[1]))); }' alexyyw.inputfile