1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Splunkで文字列を逆順にする。

Last updated at Posted at 2020-12-30

THE REVERSE CIPHERをSplunkでやってみた。

reverse.zsh
echo 'Three can keep a secret, if two of them are dead.' | rev
reverse.py
message = 'Three can keep a secret, if two of them are dead.'
message[-1::-1]

とコマンドですぐにできる逆順への並び替え。

Splunkでやろうとすると、

reverse.spl
| makeresults 
| eval message = "Three can keep a secret, if two of them are dead."
| eval counter=mvrange(1,len(message) + 1)
| stats values(message) as message by counter
| sort 0 - counter
| eval txt=substr(message,counter,1)
| streamstats count as counter
| eval counter=counter + 25
| eval counter_txt="!!".printf("%c",counter)."##"
| stats values(eval(counter_txt.txt)) as reverse values(message) as message delim=""
| rex mode=sed field=reverse "s/!!.##(.)/\1/g"
| nomv reverse

と大事になる。

理由としては

  • マルチバリューを逆順にする関数がない。
    • mvsort()はAsciiコード順にしかならない :cry:
  • フィールド単位で操作は可能だけど、フィールド内の操作する関数が少ない。
  • ループできない。
  • list()は100文字制限がある。

ということもありvalues()でなんとか整列をさせようと頑張ったのがこの形。

reverse message
.daed era meht fo owt fi ,terces a peek nac eerhT Three can keep a secret, if two of them are dead.

となんとか完成。

頻繁に使うなら、外部pythonスクリプトを用意した方がいいかもしれません。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?