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. Thanks. 8,972 4 4 gold badges 51 51 silver badges 41 41 bronze badges asked Mar 31, 2012 at 6:03 Lunar Mushrooms Lunar Mushrooms 8,758 18 18 gold badges 70 70 silver badges 91 91 bronze badges by "all whitespace", do you mean newlines as well? Commented Jun 19, 2013 at 23:54
$ 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.
In order to wipe all whitespace including newlines you can try:
cat file.txt | tr -d " \t\n\r"
You can also use the character classes defined by tr (credits to htompkins comment):
cat file.txt | tr -d "[:space:]"
For example, in order to wipe just horizontal white space:
cat file.txt | tr -d "[:blank:]"