如何复制preset5并将其粘贴到preset0?然后编辑预设0 -0.30 到 0.30 ?
import os
file_withlines = """
cat >> /tmp/test.log << \EOF
junks====================================1
otherjunks===============================0
preset0=0,2,-0.30,4
preset1=1\n,2,-0.30,4
preset2=2,2,-0.30\n,4
preset3 =3,2,-0.30,4
preset4= 4,2,-0.30,4
preset5 =5,0.2\n,-0.30,4
junksS==\n\r\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\r\r\r\r\r\rHere!\n\r
EOF
"""
os.system(file_withlines)
os.system("cat /tmp/test.log")
def read_log(findme):
f = open('/tmp/test.log', "r")
for line in f:
if "=" in line:
key,val = line.split("=",1)
if findme in key:
return val.replace("\\n", "").rstrip()
def copy_or_edit_line():
# a = os.popen("grep preset5 /tmp/test.log | head -1").read()
# sed -i s/"^slave.pcm \"hw:.*"/"slave.pcm \"hw:${out}\""/ /etc/asound.conf
print "how!"
# 1) Read
print read_log("preset5")
# 2) Copy preset5 and paste to preset0
print read_log("preset0")
# 3) Edit preset0 values 0,2,-0.30,4 to 0,2,0.30,4
print read_log("preset0")