Bash remove trailing whitespace from every line

In this article let’s discuss about Bash remove trailing whitespace from every line. Let’s go through the following methods without any delay.

Method 1:

# Basic syntax:
awk '{$1=$1};1' your_file

If you are facing any issues with the above approach then try the alternative that is given below. It may look similar by have a try!

Method 2 :

#!/bin/bash

#Make our variable
var="foo bar"

#Print it without the spaces
echo ${var//[[:blank:]]/}

#Output will be foobar

Hope the above solution works.

Realted Posts : How to create makefile in Erlang