How to squeeze multiple pipe character '|' into single '|' using sed?

Hi,

I am trying to convert multiple Unix pipe symbol or bar into single |. I have tried with the following sed statements, but, no success :(. I need it using sed only

echo "sed 's/\|\+/\|/g'
sed 's/[\|]*/\|/'
sed 's/\|*/|/'
sed -r 's/\|+/\|/' 

However, the below awk code is working fine.

awk '{gsub(/\|+/,"|")}1' 
echo '1|23||45|||6|' | sed 's/||*/|/g'
1 Like

The tr utility can do it with its -s (squeeze) option.

$ echo 'a||||b' | tr -s '|'
a|b

$

Hi vgersh99, thank you for the code. Can't I use \+ to mean one or more of this type, instead of this archaic wild-card character '*'?

@royalibrahim. \+ is a GNU extension to sed. You can use it but your command will only work with GNU sed..