I have an awk script as:
BEGIN { FS = " " }
NR == 1 {
prev = $3
}
$3 == prev {
++count
lines[++i] = $1","$2
}
$3 != prev {
print count",1"
for ( j =1; j <= i; j++)
print lines[j]
for (all in lines)
delete lines[all]
prev = $3
i = 0
lines[++i] = $1","$2
count = 1
}
which takes a file such as:
1111 2221 1 3331 44441 55551
1112 2222 1 3332 44441 55551
1113 2223 1 3333 44441 55551
1111 2221 2 3331 44442 55552
1112 2222 2 3332 44442 55552
1113 2223 2 3333 44442 55552
1111 2221 3 3331 44443 55553
1112 2222 3 3332 44443 55553
1113 2223 3 3333 44443 55553
and builds a file with total number of points where field 3 is similar and gives a header.
The output is:
3,1
1111,2221
1112,2222
1113,2223
3,1
1111,2221
1112,2222
1113,2223
3,1
1111,2221
1112,2222
1113,2223
How can I include on the first record of each group of data elements from the 5th & 6th field and create this type of file?
3,1,"44441","55551"
1111,2221
1112,2222
1113,2223
3,1,"44442","55552"
1111,2221
1112,2222
1113,2223
3,1,"44443","55553"
1111,2221
1112,2222
1113,2223
Thanks
BEGIN { FS = " " }
NR == 1 {
prev = $3
}
$3 == prev {
++count
lines[++i] = $1","$2
}
$3 != prev {
print count",1"
for ( j =1; j <= i; j++)
print lines[j]
for (all in lines)
delete lines[all]
prev = $3
i = 0
lines[++i] = $1","$2
count = 1
}
which takes a file such as:
1111 2221 1 3331 44441 55551
1112 2222 1 3332 44441 55551
1113 2223 1 3333 44441 55551
1111 2221 2 3331 44442 55552
1112 2222 2 3332 44442 55552
1113 2223 2 3333 44442 55552
1111 2221 3 3331 44443 55553
1112 2222 3 3332 44443 55553
1113 2223 3 3333 44443 55553
and builds a file with total number of points where field 3 is similar and gives a header.
The output is:
3,1
1111,2221
1112,2222
1113,2223
3,1
1111,2221
1112,2222
1113,2223
3,1
1111,2221
1112,2222
1113,2223
How can I include on the first record of each group of data elements from the 5th & 6th field and create this type of file?
3,1,"44441","55551"
1111,2221
1112,2222
1113,2223
3,1,"44442","55552"
1111,2221
1112,2222
1113,2223
3,1,"44443","55553"
1111,2221
1112,2222
1113,2223
Thanks