chalcopyrites
Technical User
Hi everyone,
I have an input file like this:
aaaaaa 8493572 384276 2348973 2453
aaaaaa 490652 903468209685 290862568 80936
aaaaaa 9856 23948573429857 39485723495873 93482
aaaaaa 83753958 84571395 34982573045 19837
bbbbbb 89347295 23497389 39824705 389427904
bbbbbb 490652 903468209685 290862568 80936
bbbbbb 9856 23948573429857 39485723495873 93482
cccccc 11111 11111 11111 11111
cccccc 39425234 8976096 759867 20348957
cccccc 3490781205 38947623 73849 893457
cccccc 048 0348q50 3984257 234908574
and would like to separate it into 3 files based on the first field.
I have got the following (cobbled together from various other bits and pieces):
BEGIN {
i=0
filename = "file"i".dat"
}
{
if (hn!=$1){
i += 1
if (filename != "") close (filename);
filename = "file"i".dat";
print "Creating File : "i
getline
}
hn=$1
}
{
print $0 > filename
}
which splits the input into 3 files based on the first field but it always misses off the first line in each sequence.
Can you tell me where I am going wrong? Awk scripts aren't my strong point!
Thanks
Erica
I have an input file like this:
aaaaaa 8493572 384276 2348973 2453
aaaaaa 490652 903468209685 290862568 80936
aaaaaa 9856 23948573429857 39485723495873 93482
aaaaaa 83753958 84571395 34982573045 19837
bbbbbb 89347295 23497389 39824705 389427904
bbbbbb 490652 903468209685 290862568 80936
bbbbbb 9856 23948573429857 39485723495873 93482
cccccc 11111 11111 11111 11111
cccccc 39425234 8976096 759867 20348957
cccccc 3490781205 38947623 73849 893457
cccccc 048 0348q50 3984257 234908574
and would like to separate it into 3 files based on the first field.
I have got the following (cobbled together from various other bits and pieces):
BEGIN {
i=0
filename = "file"i".dat"
}
{
if (hn!=$1){
i += 1
if (filename != "") close (filename);
filename = "file"i".dat";
print "Creating File : "i
getline
}
hn=$1
}
{
print $0 > filename
}
which splits the input into 3 files based on the first field but it always misses off the first line in each sequence.
Can you tell me where I am going wrong? Awk scripts aren't my strong point!
Thanks
Erica