unix - shell - Insert a character at different indexes in a string -


it part of larger script needs shell scripted. simple task in other languages, i'm having trouble accomplishing in shell. have string , want insert "." @ possible indices within string. output can on newlined or separated spaces. can help?

example:
input: "abcd"

output: ".abcd
a.bcd
ab.cd
abc.d
abcd."

or

output: ".abcd a.bcd ab.cd abc.d abcd."

a simple loop do:

input=abcd ((i=0; i<${#input}+1; i++))     echo ${input::$i}.${input:$i} done 

this slices string @ each index , inserts .. can change echo else appending array if want store them instead ouf output them, of course.


Comments

Popular posts from this blog

asp.net mvc 3 - Using mvc3, I need to add a username/password to the sql connection string at runtime -

kineticjs - draw multiple lines and delete individual line -

thumbnails - jQuery image rotate on hover -