Replace multiple occurances of same character with a single character.

Hi all,
Greetings,

I have the following scenario, The contents of main file are like :

Unix|||||forum|||||||||||||||is||||||the||best
so||||||be|||||on||||||||||||||||||||||||||||||||||||||||||||it

And i need the output in the following form:

Unix=forum=is=the=best
so=be=on=it

The logic being that multiple and consecutive occurances of the special character, here - pipe , should be replaced by a single special character.

Please guide.

Thanks,
Dipan

awk '{gsub(/[|]+/,"=")}1' file

Please learn to use [code] tags when you post code or sample data.
Thanks.

1 Like
awk '$1=$1' FS='[|]*' OFS== file
sed 's/||*/=/g' file
tr -s \| = < file
1 Like

Thanks danmero, Thanks Scrutinizer :slight_smile: