I have a text file that has the following format:
characters(that I want to keep) (space) characters(that I want to remove)
So for example:
You are putting quantifier * at the wrong place.
*
Try instead this: -
grep '^[^\s]*' text1.txt > text2.txt
or, even better: -
grep '^\S*' text1.txt > text2.txt
\S means match non-whitespace character. And anchor ^ is used to match at the beginning of the line.
\S
^