Created
September 24, 2025 14:09
-
-
Save ychaouche/a949fa440f50e7f2857b98e7e4aef594 to your computer and use it in GitHub Desktop.
column selection with awk
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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