split a file using awk

Hi ,

I just need to split a file and outputfiles are redirected to gzip file

need:

Input file - A.gz

content of A.gz is

100|sfdds|dffdds|200112|sdfdf
100|sfdds|dffdds|200112|sdfdf
100|sfdds|dffdds|200112|sdfdf
100|sfdds|dffdds|200212|sdfdf
100|sfdds|dffdds|200212|sdfdf
100|sfdds|dffdds|200212|sdfdf
100|sfdds|dffdds|200312|sdfdf
100|sfdds|dffdds|200142|sdfdf

I wanted the out files as
Output file 1- 200112.gz
100|sfdds|dffdds|200112|sdfdf
100|sfdds|dffdds|200112|sdfdf
100|sfdds|dffdds|200112|sdfdf

Output file 2- 200212.gz
100|sfdds|dffdds|200212|sdfdf
100|sfdds|dffdds|200212|sdfdf
100|sfdds|dffdds|200212|sdfdf

Output file 3- 200312.gz
100|sfdds|dffdds|200312|sdfdf

Output file 4- 200142.gz
100|sfdds|dffdds|200142|sdfdf

need ur help in doing so

Thanks,

Should be something like this:

awk -F"|" 'n != $4 {n=$4; c++} {print > c "-" $4 ".gz"}' A.gz

Hi Franklin,

The input and output files should be gzip files and are not a normal txt files

In that case you should use something like gzcat or gzip to unextract the file first. How?

You can easily search the forums using our internal Google search engine or our advanced internal search engine.