Last active
December 15, 2015 10:09
-
-
Save oranie/5243833 to your computer and use it in GitHub Desktop.
cassandra host sort by bash
This file contains 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
#!/bin/bash | |
TMP_LIST=(`nodetool -h 192.168.0.1 ring| grep 192.168 | awk '{print $1}'`) | |
TMP_LIST_LAST_NUM=`expr ${#TMP_LIST[*]} - 1` | |
SORT_LIST=() | |
SKIP_NUM="5" | |
SEQ_LAST_NUM=`expr $SKIP_NUM - 1` | |
for t in `seq 0 $SEQ_LAST_NUM` | |
do | |
for i in `seq $t $SKIP_NUM $TMP_LIST_LAST_NUM` | |
do | |
#echo ${TMP_LIST[$i]} | |
SORT_LIST+=(${TMP_LIST[$i]}) | |
done | |
done | |
echo ${SORT_LIST[@]} | |
perlならシュワルツ変換を使いましょう! | |
#!/usr/bin/perl | |
use strict; | |
use warnings; | |
my @list = qw(れい いち に さん し ご ろく なな はち きゅう とお); | |
my $base = 3; | |
my $i = 0; | |
my @sortedsurplus = map { $->[0] } | |
sort { $a->[1]%$base <=> $b->[1]%$base } | |
map { [$, $i++] } @list; | |
print “$\n” for @sorted_surplus; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment