0

I am on a mac and I am trying to set up a cron task to remove all instances of the '#' from my /etc/hosts file

I use this command:

sed 's/\#//g' /etc/hosts

which seems to work fine, but when I do this to output it to replace the content in /etc/hosts:

sed 's/\#//g' /etc/hosts > /etc/hosts

the /etc/hosts file ends up being empty. Why is it ending up empty?

RobKohr
  • 6,611
  • 7
  • 48
  • 69
  • Dupe of [Find and replace in file and overwrite file doesn't work, it empties the file](https://stackoverflow.com/questions/5171901) – Wiktor Stribiżew Nov 16 '20 at 23:43
  • or [How can I use a file in a command and redirect output to the same file without truncating it?](https://stackoverflow.com/q/6696842/3266847) – Benjamin W. Nov 16 '20 at 23:50
  • 1
    Does this answer your question? https://stackoverflow.com/a/6696877/390913 – perreal Nov 16 '20 at 23:51

0 Answers0