0

I'm trying to delete a line from a file and update the file to reflect that. I'm running a bash command inside a python program. The line delete works on the terminal, but the file isn't updated.

subprocess.call("sed -e $d {}".format(self._path).split())

How can I update the file to not have this line anymore.

Melissa Stewart
  • 3,483
  • 11
  • 49
  • 88

1 Answers1

1

Should add the -i flag to sed command to edit the file in-place.

On BSD's sed:

subprocess.call("sed -i '' -e $d {}".format(self._path).split())

On GNU's sed:

subprocess.call("sed -i -e $d {}".format(self._path).split())
Gonzalo Matheu
  • 8,984
  • 5
  • 35
  • 58