I am having problems correctly escaping a subprocess call
I want to call sed -n "$=" /path/to/file
to count the number of lines in a file but fail to do so from python. My code is as follows:
import subprocess
filename = "/path/to/file"
cmd = subprocess.Popen(["sed", "-n '$='", filename], stdout=subprocess.PIPE)
cmd_out, cmd_err = cmd.communicate()
num_lines = int(cmd_out.strip())
print num_lines
I have tried different escaping combinations for "-n '$='" but nothing seems to work.