echo 1234 | sed '
/\n/ !G
s/\(.\)\(.*\n\)/&\2\1/
//D
s/.//
'
Run Code Online (Sandbox Code Playgroud)
我无法理解上面的sed
代码。
我的理解是:
PATTERN SPACE=1234
first operation /\n/ !G ---> 1234\n(if \n is not found it is appended at th end)
s/\(.\)\(.*\n\)/&\2\1/ ----> 1234\n234\n1
//D ----> \n234\n1(deletes upto newline and commands
from the beginning are applied to the
existing pattern space)
PATTERN SPACE=\n234\n1
second operation /\n/ !G ---> skipped since \n234\n1 has newline now
s/\(.\)\(.*\n\)/&\2\1/ ----> \n234\n1234\n
//D ----> \n234\n1234\n
Run Code Online (Sandbox Code Playgroud)
看来我做错了什么。
在数字中转出数字的最佳方法是什么?
例如
$ echo 123 | hook
321
$ echo 12358 | hook
85321
Run Code Online (Sandbox Code Playgroud)