相关疑难解决方法(0)

在 sed 中反转一行?

 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)

看来我做错了什么。

sed

6
推荐指数
1
解决办法
3304
查看次数

如何在bash中反转由数字组成的字符串?

在数字中转出数字的最佳方法是什么?

例如

$ echo 123 | hook
321
$ echo 12358 | hook
85321 
Run Code Online (Sandbox Code Playgroud)

bash string shell-script

6
推荐指数
2
解决办法
2万
查看次数

标签 统计

bash ×1

sed ×1

shell-script ×1

string ×1