sed Tip: Delete All Blank White Spaces

www.la‮c.iruttu‬om
sed Tip: Delete All Blank White Spaces

To delete all blank white space (including spaces, tabs, and newlines) from input using sed, you can use the following command:

sed '/^\s*$/d'

This command will search the input for lines that consist only of zero or more white space characters (denoted by the \s* pattern), and delete them. The ^ and $ characters specify that the search should be performed at the beginning and end of the line, respectively. The d command tells sed to delete the matching lines.

For example, if you have the following input:

This is a test.

This is another test.

Running the sed command above will output:

This is a test.
This is another test.

You can also use the tr command to delete all white space characters from a file:

tr -d '[:space:]' < input_file > output_file

This will delete all white space characters (including spaces, tabs, and newlines) from the input_file, and write the resulting output to output_file.

By using the /^\s*$/d command in sed or the tr command, you can delete all blank white space from input. This can be useful for processing text data or for removing unnecessary characters from a script.

Created Time:2017-10-30 14:27:35  Author:lautturi