Sed to remove everything after "." in file using * command?

Either escape the . with a backslash to get a literal ., or use brackets to define a character class:

sed 's/\..*$//' data.txt > cleaned.txt
sed 's/[.].*$//' data.txt > cleaned.txt

You tried 's/\.*//', which is "zero or more literal dots", which is different from "literal dot followed by zero or more of anything", i.e. 's/\..*//'. I also added a $ for good measure.


This is the simplest:

sed "s/\..*//"

And this is, I think, one of the best ways of doing it (better than pure bash or Python).

Tags:

Bash

Sed