Sed diffrent replace by occurrence

I couldn't find the answer anywhere, so I hope you could help me.
I need to change something like the following:
something/bla/aaaa
anything/bbb
to:
something
--bla
----aaaa
anything
--bbb

How do I do this?
Is it possible with sed?
I tried various patterns, but don't know how to change next occurence to something else then I changed the first occurence.
Hope it doesn't sound too pell-mell and you know what I mean.

hope this will help you.

awk -F"/" '{a="";for(i=1;i<=NF;i++){print a""$i;a=(a "-")}}' filename.txt
1 Like

Try this...

awk -F"/" '{p=0;for(i=1;i<=NF;++i){j=p;while(j-->0){printf "-"}p+=2;print $i}}' input_file

--ahamed

1 Like

Sed as requested by OP, maybe there is a shorter way to regex this in sed, but anyhow, here is what I have:

sed -ne 's/\(.*\)\(\/\)\(.*\)\(\/\)\(.*\)/\1\n--\3\n----\5/p;s/\(.*\)\(\/\)\(.*\)/\1\n--\3/p' 

Here is the test output:

If the data pasted by the OP is fixed then the following sed will suffice...

sed 's!/!\n--!;s!/!\n----!' input_file

else use the AWK solution in post#3...

--ahamed

1 Like

Awesome!
It works perfectly, thank you very much for the help.

Unfortunately the data is not fixed, so I had to use awk.
Anyway, tarun agrawal, ahamed101, your solutions work excellent.