Spliting file based field pattern

Hi all,

i have file that looks like as below

2263881188,24570896,439,SOLO,SOLO_UNBEATABLE,E,+3.13,+0.00
2263881964,24339077,439,SOLO,SOLO_UNBEATABLE,F,-0.67,+0.00
2263883220,22619162,228,Bell,Bell_MONTHLY,E,-2.04,+0.00
2263883220,22619162,228,Bell,Bell_MONTHLY,F,-2.04,+0.00
2267475054,23627758,213,Bell,Bell_BB,F,-6.89,+0.00
2267477589,22625847,230,Bell,Bell_BB,F,-7.31,+0.00

i have huge reocrd like this in file say file1

i want to split this file with pattern say SOLO_UNBEATABLE,E into one file say SOLO_UNBEATABLE_E

SOLO_UNBEATABLE,F into other file SOLO_UNBEATABLE_F

and Bell_MONTHLY,E into seperate file Bell_MONTHLY_E and so on

all the matched pattern records should into corresponding file.

Please let me know if any awk script to do that ..

awk -F"," -v OFS="," ' { print > $5"_"$6 } ' file

Thanks a lot ! :slight_smile:

#!/usr/bin/perl
use strict;
use warnings;

my ($file, $i, @line);

$file="file.txt";

open(FILE,"<",$file, $file);
foreach $i (<FILE>){
	@line=split(/,/,$i);
	open(FILESPLIT,">>","$line[4]_$line[5]");
	print FILESPLIT "@line\n";
	close(FILESPLIT);
}
close(FILE);