Replace the period with the dash via the command line?


Here's my current command:

sed 's/\./-/' file.txt > CLEANED.txt

What I'm trying to do is replace all periods in my file with a dash. Some lines have multiple periods and I need all of them replaced with a dash - but the command above seems to just replace the first one in each line.

What am I doing wrong for it to not replace all of the periods?

In perl, just add the /g modifier to your regex:

perl -pe 's/\./-/g' file.txt > CLEANED.txt



  • -p: Creates a while(<>){...; print} loop for each “line” in your input file.
  • -e: Tells perl to execute the code on command line.