Skip to content

Instantly share code, notes, and snippets.

@ychaouche
Created September 24, 2025 14:09
Show Gist options
  • Save ychaouche/a949fa440f50e7f2857b98e7e4aef594 to your computer and use it in GitHub Desktop.
Save ychaouche/a949fa440f50e7f2857b98e7e4aef594 to your computer and use it in GitHub Desktop.
column selection with awk
BEGIN {
split(COLS,columns_array,",");
for (i in columns_array){
col=columns_array[i];
n=split(col,range,"-");
if (n>1) {
min=range[1];
max=range[2];
if (!min) {
min=1
}
if (!max) {
gotonf=1;
}
for (j=min;j<=max;j++)
extended_array[k++]=j
}
else {
extended_array[k++]=col;
}
}
# for (k=0;k < length(extended_array); k++) {
# # printf("%s,",extended_array[k]);
# }
# print "";
}
{
for (k=0;k < length(extended_array); k++) {
printf("%s ",$extended_array[k]);
}
if (gotonf){
lastcol=min
while (lastcol<=NF){
printf("%s ",$(lastcol++));
}
}
print "";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment