Issue
With this data
aaa:
- bbbb: ccc ddd' {eeee [fff
kkk: mmm nnn" oo pp
I like to have removed all duplicate spaces after the first :
aaa:
- bbbb: ccc ddd' {eeee [fff
kkk: mmm nnn" oo pp
Using \b
doesn't help here.
Solution
With perl
(assuming there's only one :
per line):
$ perl -pe 's/ +(?!.*:)/ /g' ip.txt
aaa:
- bbbb: ccc ddd' {eeee [fff
kkk: mmm nnn" oo pp
If you can have multiple :
but you still want to squeeze multiple spaces after the first :
, you can use this:
perl -pe 's/^[^:]+(*SKIP)(*F)| +/ /g'
With sed
:
$ sed -E ':a s/^([^:]+:.*) {2,}/\1 /; ta' ip.txt
aaa:
- bbbb: ccc ddd' {eeee [fff
kkk: mmm nnn" oo pp
:a
is a label for the substitute command. As long as a match is found, ta
will jump to the label, thus replacing all possible matches.
Answered By - Sundeep Answer Checked By - Robin (WPSolving Admin)