Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
使用 sed,如何更改输入字符串,例如9872在输入字符串39 38 37 32 的每个数字之前插入数字 3 并在每个数字之后插入空格9872.
9872
39 38 37 32
9872.
输入字符串:
所需输出:
echo 9872 | sed 's/./3&\ /g'
并且只是为了完整性,使用正则表达式引用的更通用方式。
echo 9872 | sed -r 's/([[:digit:]])/3\1 /g'
$ echo "9872" | sed 's/[0-9]/3& /g' 39 38 37 32