首页 > 解决方案 > Shell:在字母数字字符后添加换行符

问题描述

我需要在以下段落中的字母数字字符(例如:11.34s)之后添加一个换行符 - 在 Shell 中

输入:

zip_upload : Unzipping the new release at /path - 338.17s Gathering Facts --------------------------------------------------------- 4.78s zip_upload : Upload the zipped binaries to repository ---------- 2.48s zip_upload : Find the file applicatons.yml in remote node ------ 1.87s zip_upload : Upload to repository ---------------------- 0.92s zip_upload : include_tasks ------------------------------------------- 0.71s

需要的输出如下:

zip_upload : Unzipping the new release at /path - 338.17s
Gathering Facts --------------------------------------------------------- 4.78s
zip_upload : Upload the zipped binaries to repository ---------- 2.48s
zip_upload : Find the file applicatons.yml in remote node ------ 1.87s
zip_upload : Upload to repository ---------------------- 0.92s
zip_upload : include_tasks ------------------------------------------- 0.71s 

请帮忙

标签: shellsed

解决方案


单程:

sed -r "s/([0-9]\.[0-9][0-9]s) /&\n/g" file

这个 sed 寻找一个模式[digit].[digit][digit]s,然后用模式匹配(&)替换,然后是换行(\n)。


推荐阅读