I'm trying to replace the first x number of spaces in a line with a |. Right now I'm using a very inefficient syntax to accomplish the task and was looking to simplify it.
I have several cases were the pipes need to replace just the first space on the line, which I did a simple replace. I am doing this while reading each line of a file that I'm cat'ing.
v_sec=`echo $line | sed 's/ /|/'`
The ugly code comes in when I need to replace the first 11 spaces with pipes and ended up doing this:
v_bar1=`echo $line | sed 's/ /|/'`
v_bar2=`echo $v_bar1 | sed 's/ /|/'`
v_bar3=`echo $v_bar2 | sed 's/ /|/'`
v_bar4=`echo $v_bar3 | sed 's/ /|/'`
v_bar5=`echo $v_bar4 | sed 's/ /|/'`
v_bar6=`echo $v_bar5 | sed 's/ /|/'`
v_bar7=`echo $v_bar6 | sed 's/ /|/'`
v_bar8=`echo $v_bar7 | sed 's/ /|/'`
v_bar9=`echo $v_bar8 | sed 's/ /|/'`
v_bar10=`echo $v_bar9 | sed 's/ /|/'`
v_bar_final=`echo $v_bar10 | sed 's/ /|/'`
and there is this, but it falls short at 9 (Is there a newer sed with more \(\) tags? They changed regex, why not this and the silly 2 digit \{\} limit?):