how to remove spaces at end of line linux 1

how to remove spaces at end of line linux

Use either one of both next commands with sed 's/to_replace/replace/':
sed 's/ *$//' file
sed 's/[[:blank:]]*$//' file

Here is what the above code is Doing:
1. sed ‘s/ *$//’ file

s/ *$//

s is the substitute command of sed for find and replace

*$//

* is a regular expression for zero or more of the preceding character
$ is a regular expression for the end of the line
// is the replacement string

2. sed ‘s/[[:blank:]]*$//’ file

s/[[:blank:]]*$//

s is the substitute command of sed for find and replace

[[:blank:]]*$//

[[:blank:]] is a regular expression for any whitespace character
* is a regular expression for zero or more of the preceding character
$ is a regular expression for the end of the line
// is the replacement string

Similar Posts