Unix 中的单行输入到多行输出

Jur*_*nao 1 unix

我如何使用过滤器来显示如下内容:

echo "你好" |

H
e
l
l
o

t
h
e
r
e
Run Code Online (Sandbox Code Playgroud)

ter*_*don 11

这是一对夫妇:

  1. fold

    echo "Hello there" | fold -w 1
    H
    e
    l
    l
    o
    
    t
    h
    e
    r
    e
    
    Run Code Online (Sandbox Code Playgroud)
  2. 珀尔

    echo "Hello there" | perl -pe 's/(.)/$1\n/g;'
    H
    e
    l
    l
    o
    
    t
    h
    e
    r
    e
    
    Run Code Online (Sandbox Code Playgroud)


use*_*ser 5

您可以使用它sed来执行此操作。它比 perl 轻一些,但仍然允许您使用正则表达式来表达您的内心愿望。

$ echo "Hello world" | sed -r 's/./&\n/g'
H
e
l
l
o

w
o
r
l
d
Run Code Online (Sandbox Code Playgroud)