且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何使用bash脚本将一行中的某些重复模式分成多行?

更新时间:2023-08-28 15:27:22

您可以像这样使用sed:

You can use sed like this:

解决方案:

s =''1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4''
p =''1 2 3 4''
echo"

s=''1 2 3 4 1 2 3 4 1 2 3 4 1 2 3 4''
p=''1 2 3 4''
echo "


s" | sed"s/
s"|sed "s/


p \ s */& \ n/g"
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4
p\s*/&\n/g"
1 2 3 4
1 2 3 4
1 2 3 4
1 2 3 4



您可以使用无限while循环,并使用输入文件并遍历每一行,以便将此逻辑用于多行.

实时演示
http://ideone.com/P59OCJ [



You can use infinite while loop and use the input file and iterate through each line to use this logic for murtiple lines.

Live Demo
http://ideone.com/P59OCJ[^]