How Do I Remove Leading Spaces in Unix?
Contents Use Sed ‘S/^ *//G’, to Remove the Leading White Spaces. There Is Another Way to Remove Whitespaces Using `Sed` Command. the Following Commands Removed...
Use sed ‘s/^ *//g’, to remove the leading white spaces. There is another way to remove whitespaces using `sed` command. The following commands removed the spaces from the variable, $Var by using `sed` command and [[:space:]]. $ echo “$Var are very popular now.”
How can I remove the leading spaces from a string?
String result = str. trim(); The trim() method will remove both leading and trailing whitespace from a string and return the result.
Must Read
How do I remove extra spaces in Unix?
sed command:
The 1st command removes the leading spaces, the second removes the trailing spaces and the last replaces a group of spaces with a single space. The source file itself can be updated by using the -i option of sed.