Lunar Mushrooms Lunar Mushrooms - 6 months ago 10
Linux Question

How to remove all white spaces from a given text file

I want to remove all the white spaces from a given text file. Is there any shell command available for this ? Or, how to use

sed
for this purpose.

I want something like below:


$ cat hello.txt | sed ....


I tried this :
cat hello.txt | sed 's/ //g'
.But it removes only spaces, not tabs.

Answer
$ man tr
NAME
    tr - translate or delete characters

SYNOPSIS
    tr [OPTION]... SET1 [SET2]

DESCRIPTION
   Translate, squeeze, and/or delete characters from standard 
   input, writing to standard output.

You can try:

cat file.txt | tr -d " \t\n\r"