2008/05/13

sed tips - compressing space

Assume in.txt contains an output of dpkg -l, for example:
ii zip 2.32-1 Archiver for .zip files
To compress the line to single space character in between the columns, we can use this sed pattern for replacing extra spaces to one space:
cat in.txt | sed -e "s/[ ][ ][ ]*/ /g"
This will replace the consecutive spaces to one space.