A Generic version for any number/position of spaces in awk:
awk -v s='2,4' '{f=!split(s,a,",");for(i in a){r="^.{"a[i]+f++"}";gsub(r,"& ")}}1' 00 11 22 abc def ghi ⋮
A more powerful version, where other characters than space can be inserted:
spacers(){ awk -v s="$1" '{f=!split(s,a,/[^*0-9]*/);split(s,p,/[*0-9]*/); for(i in a){if(""==b=a[i])continue; r="^.{"(b!="*"?b+f++:length($0))"}"; gsub(r,"&"p[i+1])}} 1' $2;}
That way, you can do e.g.:
spacers '0|2 4 6|[email protected] |* |' file |00 11 22| [email protected] | def ghi |
which is great for creating org-mode tables and piping directly to clipboard.
Note: The shell-function also accepts data through STDIN.
(Earlier versions of this answer contained a generic awk-solution, that used sed for the final replace)
certain column
alwaysfirst column
or are you looking for a solution that lets you specific which column to space by it's number?