Hướng dẫn dùng sed newline python

I am having an issue with newlines in my command which involves the use of sed.

The scenario is as follows. When I execute the following command from Bash, I get:

cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed -e s/ph/\\nPH/g | grep -v ^$

PHysical id : 0core id      : 0
PHysical id : 0core id      : 1

As you can see, the sed command replaced ph with \nPH, such that I get a new line for each 'physical id...'

Now, I am calling this bash command from Python. Here is a small snippet of my code containing all relevant library imports.

import subprocess
cmd = 'cat /proc/cpuinfo | egrep "core id|physical id" | tr -d "\n" | sed -e s/ph/\\nPH/g | grep -v ^$ '
subprocess.call(cmd, shell=True, universal_newlines=True, stdin=subprocess.PIPE)

The problem is that I get:

nPHysical id    : 0core id      : 0nPHysical id : 0core id      : 1

on one line. It appears that the '\n' is not processed as the letter n is printed before PH.

I need to get the output nicely printed so that I can later add | sort | uniq | wc -l to my command to count the lines.

I would appreciate some help from the Bash-and-Python gurus out there.

Thank you.