【发布时间】:2013-12-19 15:12:02
【问题描述】:
我想得到这个字符串 -> Example example1
以这种形式:
E
x
a
m
p
l
e
e
x
a
m
p
l
e
1
【问题讨论】:
标签: string bash character line cut
我想得到这个字符串 -> Example example1
以这种形式:
E
x
a
m
p
l
e
e
x
a
m
p
l
e
1
【问题讨论】:
标签: string bash character line cut
将fold utility 与width=1 一起使用:
echo 'Example example1' | fold -w1
E
x
a
m
p
l
e
e
x
a
m
p
l
e
1
另一个选项是grep -o:
echo 'Example example1' | grep -o .
E
x
a
m
p
l
e
e
x
a
m
p
l
e
1
【讨论】:
fold的完美配方!
使用标准的 unix 工具,您可以这样做,例如:
echo "Example example1" | sed 's/\(.\)/\1\n/g'
使用纯 bash:
echo "Example example1" | while read -r -n 1 c ; do echo "$c"; done
【讨论】: