Hi ,
I am getting a string like
aaa,bbb,sdsdad,sdfsdf,sdfsdfdsf,rtyrtyr,45654654,ddfdfdfgdfg,dfgdfgdg..........
.
Now what I need is to format it.
So after each nth comma I need one newline. So the above will look like
when n=3
aaa,bbb,sdsdad,
sdfsdf,sdfsdfdsf,rtyrtyr,
45654654,ddfdfdfgdfg,dfgdfgdg...........
Please help.
bmk
2
Try like...
echo "aaa,bbb,sdsdad,sdfsdf,sdfsdfdsf"| sed 's/,/&\n/3'
RudiC
4
Does it? Try with longer strings... and try this:
echo "aaa,bbb,sdsdad,sdfsdf,sdfsdfdsf,wer,345,dh,zhrhzr6,rtz,zr"| sed -r 's/([^,]*,){3}/&\n/g'
If your sed does not accept the -r option, try this:
echo "aaa,bbb,sdsdad,sdfsdf,sdfsdfdsf,wer,345,dh,zhrhzr6,rtz,zr"| sed 's/[^,]*,[^,]*,[^,]*,/&\n/g'
1 Like
I know what you mean
I tried with longer string 1st time... then got the issue... posted not working .. then I got work around and edited that to working
Your one working like a charm .. even better than my work around. Thank you