gpt4 book ai didi

linux - 如何在 shell 脚本中的每个字符后插入一个新行?

转载 作者:塔克拉玛干 更新时间:2023-11-02 23:33:53 27 4
gpt4 key购买 nike

假设我有以下字符串:

abcdefghi

我可以使用哪个命令使结果是:

a
b
c
d
e
f
g
h
i

我刚开始编码,所以我希望有人能帮助我。

最佳答案

有一个工具叫做 fold 插入换行符,你可以告诉它在每个字符后添加一个:

$ fold -w 1 <<< 'abcdefghi'
a
b
c
d
e
f
g
h
i

<<<用于表示 here string .如果您的 shell 不支持,您可以通过管道传输到 fold相反:

echo 'abcdefghi' | fold -w 1

关于linux - 如何在 shell 脚本中的每个字符后插入一个新行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43792905/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com