sed formatting query2

i wish to remove "#" characters and replace them with a single # character. how to do that?
ex if the file is like

####aasd
##pqr
###pqr
#qwert

output shud be

#aasd
#pqr
#pqr
#qwert

plz hlp

sed 's/##*/#/g' filename
sed 's/#\{1,\}/#/g' file

Hi.

With some versions of sed you can use extended regular expressions, which can make the often inscrutable sed scripts slightly easier to read. Either as shown here or with -r:

#!/bin/sh

# @(#) s1       Demonstrate extended regular expressions in sed.

FILE=${1-data1}

sed --regexp-extended 's/#+/#/g' $FILE

Producing on your data in data1:

% ./s1
#aasd
#pqr
#pqr
#qwert

cheers, drl

tr -s '#' < filename