[Linux] For deleting tab characters and spaces, tr command with -d option is simple and recommended

Tadashi Shigeoka ·  Fri, March 11, 2016

In Linux, deleting tab characters and spaces can be easily done by adding the -d option to the tr command.

Linux
# Delete tab characters
tr -d '\	'

# Delete half-width spaces
tr -d ' '

The tr command can also be used on Mac, so it’s recommended for Mac users too.

Here’s how to use the tr command:

tr  Bulk character conversion

Syntax tr [Option] set1 [set2]

Options -c Replace set1 with characters not included in set1 -d Delete characters in set1 -s Replace consecutive identical characters with a single character -t Adjust set1 to the same string length as set2 set1 Specify a set of characters set2 Specify a set of characters

That’s all from the Gemba.