I have a file like this :
Mainfile:
Record|1111|ABC
text in between for record 1
text in between for record 1
Record|2222|XYZ
text in between for record 2
Record|3333|XYZ
text in between for record 3
I want to create smaller files which contains each record data
File : 1111
Record|1111|ABC
text in between for record 1
text in between for record 1
File : 2222
Record|2222|XYZ
text in between for record 2
File : 3333
Record|3333|XYZ
text in between for record 3
Currently I am using awk to do this :
awk -F"|" '
/Record/{
if(s>0) {
print line > r;
}
s=1;
r=$2;
line=$0
}
!/Record/
{
line=line"\n"$0;
}
END
{
print line > r;
}' file
But it is taking more time to process the file. Each file is 4GB in size and will contain around 75k+ Records.
Is there any faster way to do this ?