split a sentence and seperate into two lines

Hi,

I have a string as
str="route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234 Route True route net,-hopcount,0,-netmask,255.255.248.0,0,10.230.23.254 Route True"

I need to split this string into two lines as
route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234 Route True
route net,-hopcount,0,-netmask,255.255.248.0,0,10.230.23.254 Route True

How can I do that?

#!/usr/bin/perl
use strict;
my $str="route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234 Route True route net,-hopcount,0,-netmask,255.255.248.0,0,10.230.23.254 Route True";
$str=~ s/(?=route net)/\n/g;
print $str;

thanks for the reply summer_cherry ...

I forgot to mention that I want the solution in shell scripting ...

And next question will be: What shell ?

str="route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234 Route True route net,-hopcount,0,-netmask,255.255.248.0,0,10.230.23.254 Route True"
# awk '{sub("True route","True\nroute")}1' <<< "$str"
route net,-hopcount,1,255.255.255.0,10.230.20.111,10.230.20.234 Route True
route net,-hopcount,0,-netmask,255.255.248.0,0,10.230.23.254 Route True


.. or
# sed 's/True route/True\
route/' <<< "$str"

Hope this also will work..

:slight_smile:

sed 's/True/True\|/g' inputfile|awk -F\\"|" '{print $1"\n"$2}'

Thanks
Sha