Using the input file, I will like to generate the desired output.
I am trying to figure out how to get exactly the desired output results, using the code shown below.
The information in the column 2 for input file needs to be in output file from column 21 to 80, filling all this range.
Output desired:
X52152 1214-1216,1218-1221,1233,1222,1245,1223,1246,1249,1251,
X52152 1224-1232,1234-1243,1247,1250,1253-1254,1332,1331,1333-1336,
X52152 1338,1337,1339-1340,1467.
X52155 1215-1216,1218-1221,1233,1222,1245,1223,1246,1249,1251,1248,
X52155 1224-1232,1234-1243,1247,1250,1253-1254,1332,1331,1333-1336,
X52155 1338,1337,1339-1341.
Here the code used.
awk '
function range_to_out() {
out=(out sep (start == last ? start : (start "-" last)))
}
function print_out() {
printf "%s %s\n", p1, out","
}
NR == 1 { start=last=$2; p1=$1; next }
{
if ($2 == last+1) { last=$2 } else {
range_to_out(); sep=","; start=last=$2
}
}
$1 != p1 || length(out) > 50 { print_out(); sep=out=""; p1=$1 }
END { range_to_out(); print_out() }
' file
this question is similar to one done previously, were i got an code from Mr.glenn jackman. Here his code. this code works perfectly with other input file using single column.
awk '
function printrange() { print start (start == last ? "" : "-" last) }
NR == 1 {start=last=$1; next}
$1 == last+1 {last=$1; next}
{printrange(); start=last=$1}
END {printrange()}
' file | paste -sd" " | fold -sw 60 | tr ' ' ',' | sed 's/^/111111 /'
Thanks in advance.
Input file
X52152 1214
X52152 1215
X52152 1216
X52152 1218
X52152 1219
X52152 1220
X52152 1221
X52152 1233
X52152 1222
X52152 1245
X52152 1223
X52152 1246
X52152 1249
X52152 1251
X52152 1224
X52152 1225
X52152 1226
X52152 1227
X52152 1228
X52152 1229
X52152 1230
X52152 1231
X52152 1232
X52152 1234
X52152 1235
X52152 1236
X52152 1237
X52152 1238
X52152 1239
X52152 1240
X52152 1241
X52152 1242
X52152 1243
X52152 1247
X52152 1250
X52152 1253
X52152 1254
X52152 1332
X52152 1331
X52152 1333
X52152 1334
X52152 1335
X52152 1336
X52152 1338
X52152 1337
X52152 1339
X52152 1340
X52152 1467
X52155 1215
X52155 1216
X52155 1218
X52155 1219
X52155 1220
X52155 1221
X52155 1233
X52155 1222
X52155 1245
X52155 1223
X52155 1246
X52155 1249
X52155 1251
X52155 1248
X52155 1224
X52155 1225
X52155 1226
X52155 1227
X52155 1228
X52155 1229
X52155 1230
X52155 1231
X52155 1232
X52155 1234
X52155 1235
X52155 1236
X52155 1237
X52155 1238
X52155 1239
X52155 1240
X52155 1241
X52155 1242
X52155 1243
X52155 1247
X52155 1250
X52155 1253
X52155 1254
X52155 1332
X52155 1331
X52155 1333
X52155 1334
X52155 1335
X52155 1336
X52155 1338
X52155 1337
X52155 1339
X52155 1340
X52155 1341