Skip to content

Instantly share code, notes, and snippets.

@songpp
Last active September 9, 2016 09:50
Show Gist options
  • Select an option

  • Save songpp/7047eacf05f1c9989a6dfee1778e521d to your computer and use it in GitHub Desktop.

Select an option

Save songpp/7047eacf05f1c9989a6dfee1778e521d to your computer and use it in GitHub Desktop.
echo 1,2,4,5,6,9 a,b,d,e,f,i | gawk '{
split($1, Number, ",");
split($2, Letter, ",");
fourIdx = -1;
nineIdx = -1;
for(x = 1; x <= length(Number); x++) {
if(Number[x] == 4) {
fourIdx = x;
}
if(Number[x] == 9) {
nineIdx = x;
}
}
}
END {
if(nineIdx > fourIdx) {
idx = fourIdx;
sep = "";
nums = "";
letters = "";
while(idx <= nineIdx) {
nums = nums sep Number[idx];
letters = letters sep Letter[idx];
idx ++;
sep = ","
}
print nums " " letters;
}
}'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment