如何获取PID的值?并将格式改为:
pid: 12032
pid: 11948
文件内容:
# cat /tmp/log.txt
["", "whoami", "Copyright2024", "", "", "git.exe pid: 12032 type: File 164: E:\\tmp\\", "git.exe pid: 11948 type: File 12C: E:\\tmp\\"]
您可以使用以下代码从给定文本中提取 pid
---
- name: To get PID from log.txt
hosts: 127.0.0.1
tasks:
- name: Extract PID
shell: "grep -o 'pid: [0-9]\\+' /tmp/log.txt > /tmp/pid.txt"