Lunar Mushrooms Lunar Mushrooms - 1 year ago 57
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

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 Source
$ man tr
    tr - translate or delete characters

    tr [OPTION]... SET1 [SET2]

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

You can try:

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