sed Tip: Delete All Blank White Spaces

You can use the following sed command to delete all blank spaces in a file:

sed 's/ *//g' filename > outputfile

This command replaces all occurrences of zero or more spaces with nothing. The > outputfile redirects the output to a new file called outputfile. If you want to modify the original file in place, use the -i option:

sed -i 's/ *//g' filename

Note: The -i option modifies the file directly, so be careful when using it. It’s always a good idea to make a backup of the original file before using sed -i.

Leave a Comment