How does one convert 4 spaces into 2 spaces with sed? Is it possible?
I found this but it converts tab to spaces:
sed -r ':f; s|^(\t*)\s{4}|\1\t|g; t f' file
|
How does one convert 4 spaces into 2 spaces with I found this but it converts tab to spaces:
|
|||
|
|
|
The script you posted converts 4*n spaces to n tabs, only if those spaces are preceded only by tabs. If you want to replace 4 spaces by 2 spaces, but only in indentation, while it's possible to do it with sed, I recommend Perl instead.
In sed:
You may want to use |
|||
|
|
|
Doesn't the straight forward way work:
If not, post some input where it fails. |
|||
|
|
|
If only leading spaces are to be converted:
Also look at vim's |
|||||
|