How Do I Remove Extra Spaces in Unix?
Contents How Do I Get Rid of Extra Spaces in Linux? `Sed` Command Is Another Option to Remove Leading and Trailing Space or Character from the String Data. the...
Contents
How do I get rid of extra spaces in Linux?
`sed` command is another option to remove leading and trailing space or character from the string data. The following commands will remove the spaces from the variable, $myVar using `sed` command. Use sed ‘s/^ *//g’, to remove the leading white spaces. There is another way to remove whitespaces using `sed` command.
How do I remove blank spaces in Unix?
Simple solution is by using grep (GNU or BSD) command as below.
- Remove blank lines (not including lines with spaces). grep . file.txt.
- Remove completely blank lines (including lines with spaces). grep “S” file.txt.