reverse the order of characters in a string

后端 未结 13 1037
逝去的感伤
逝去的感伤 2020-12-04 15:03

In string \"12345\", out string \"54321\". Preferably without third party tools and regex.

13条回答
  •  Happy的楠姐
    2020-12-04 15:49

    rev | tail -r (BSD) or rev | tac (GNU) also reverse lines:

    $ rev <<< $'12\n34' | tail -r
    43
    21
    $ rev <<< $'12\n34' | gtac
    43
    21
    

    If LC_CTYPE is C, rev reverses the bytes of multibyte characters:

    $ LC_CTYPE=C rev <<< あの
    ��め�
    $ export LC_ALL=C; LC_ALL=en_US.UTF-8 rev <<< あの
    のあ
    

提交回复
热议问题