sed command execution in Python

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












command = '''out=$(%s);echo $out | sed -n 's/.*"Id": "(.*)", "Created".*"Status": "(.*)", "Running".*"Pid": (.*),.*"ExitCode": (.*), "Error".*"Name": "/(.*)", "RestartCount".*"Privileged": (.*), "PublishAllPorts".*"Cmd": (.*), "Image": "(.*)", "Volumes".*/1;2;3;4;5;6;7;8/p' ''' %out

runcmd = self.srv.execute(command)

received runcmd = ['x01;x02;x03;x04;x05;x06;x07;caspian/fabric-registry:2.3.1.0-58.3a6dfafn'] .


only 8thkey is correctly assigned ..Remaining all from 1 to 7 are not assigned with its value from out.Why is it so ?



Help would be much appreciated



where as out =
[

"Id": "e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e",
"Created": "2018-10-01T05:34:37.972705474Z",
"Path": "./boot.sh",
"Args": [
"lifecycle"
],
"State":
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 95168,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-10-01T05:34:51.739952918Z",
"FinishedAt": "2018-10-01T05:34:46.361850627Z"
,
"Image": "sha256:328eab472dbd625983c23f8760bc3d0b595dd161ee0d12e1d6d53c8b70228fd1",
"ResolvConfPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hostname",
"HostsPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hosts",
"LogPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e-json.log",
"Name": "/fabric-lifecycle",
"RestartCount": 0,
"Driver": "devicemapper",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig":
"Binds": [
"/opt/emc/caspian/fabric/agent/services/fabric/data:/data:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log:/var/log:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data:/host/data:ro",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files:/host/files:ro"
],
"ContainerIDFile": "",
"LogConfig":
"Type": "json-file",
"Config":
,
"NetworkMode": "host",
"PortBindings": null,
"RestartPolicy":
"Name": "",
"MaximumRetryCount": 0
,
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 1073741824,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": -1,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
,
"GraphDriver":
"Data":
"DeviceId": "119",
"DeviceName": "docker-254:0-354418880-9759c901ef5109a23a913840bd789fa6934ac18a4688ba60cabbad13b15078b8",
"DeviceSize": "10737418240"
,
"Name": "devicemapper"
,
"Mounts": [

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data",
"Destination": "/host/data",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files",
"Destination": "/host/files",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/data",
"Destination": "/data",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log",
"Destination": "/var/log",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"

],
"Config":
"Hostname": "provo-burlywood",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ZYPPER=zypper --no-gpg-checks --non-interactive",
"JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-oracle/",
"APPLICATION=fabric",
"ROLE=lifecycle",
"VERSION=3.3.0.0-3594.2b8e92d",
"DOCKER_FIX= "
],
"Cmd": [
"lifecycle"
],
"Image": "caspian/fabric:3.3.0.0-3594.2b8e92d",
"Volumes": null,
"WorkingDir": "/opt/emc/caspian/fabric/lifecycle",
"Entrypoint": [
"./boot.sh"
],
"OnBuild": null,
"Labels":
,
"NetworkSettings":
"Bridge": "",
"SandboxID": "683a8af8564b3083ac766b7065d5c84315ae8d2d0898c5099baccf2e137e7ca6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": ,
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks":
"host":
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "d8f7b03c732d5c57d170d76211c33710a17c8f670a5d8c9ebb91a0bdc2f8bb46",
"EndpointID": "ef788fd7eaa43369a184287c88ea19a7f5f369c808d3af40b9df41579a1251a6",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null




]


Expected output:



id, state, pid, exitCode, name, privileged, cmdLine, image = 'e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e;running;95168;0;fabric-lifecycle;false;[ "lifecycle" ];caspian/fabric:3.3.0.0-3594.2b8e92d;1073741824'.split(';)**









share|improve this question









New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 4




    Rather than executing an external shell command to do your substitution, this strikes me as something that Python should be able to do a lot quicker by itself.
    – Kusalananda
    Oct 4 at 12:11






  • 2




    I agree with @Kusalananda, python is taillored to parse input string for values and format an output string. You should make a new question in stackoverflow, please specifiy a sample input string (out value in your code) and an expected output (runcmd in your code).
    – Archemar
    Oct 4 at 12:34














up vote
0
down vote

favorite












command = '''out=$(%s);echo $out | sed -n 's/.*"Id": "(.*)", "Created".*"Status": "(.*)", "Running".*"Pid": (.*),.*"ExitCode": (.*), "Error".*"Name": "/(.*)", "RestartCount".*"Privileged": (.*), "PublishAllPorts".*"Cmd": (.*), "Image": "(.*)", "Volumes".*/1;2;3;4;5;6;7;8/p' ''' %out

runcmd = self.srv.execute(command)

received runcmd = ['x01;x02;x03;x04;x05;x06;x07;caspian/fabric-registry:2.3.1.0-58.3a6dfafn'] .


only 8thkey is correctly assigned ..Remaining all from 1 to 7 are not assigned with its value from out.Why is it so ?



Help would be much appreciated



where as out =
[

"Id": "e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e",
"Created": "2018-10-01T05:34:37.972705474Z",
"Path": "./boot.sh",
"Args": [
"lifecycle"
],
"State":
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 95168,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-10-01T05:34:51.739952918Z",
"FinishedAt": "2018-10-01T05:34:46.361850627Z"
,
"Image": "sha256:328eab472dbd625983c23f8760bc3d0b595dd161ee0d12e1d6d53c8b70228fd1",
"ResolvConfPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hostname",
"HostsPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hosts",
"LogPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e-json.log",
"Name": "/fabric-lifecycle",
"RestartCount": 0,
"Driver": "devicemapper",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig":
"Binds": [
"/opt/emc/caspian/fabric/agent/services/fabric/data:/data:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log:/var/log:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data:/host/data:ro",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files:/host/files:ro"
],
"ContainerIDFile": "",
"LogConfig":
"Type": "json-file",
"Config":
,
"NetworkMode": "host",
"PortBindings": null,
"RestartPolicy":
"Name": "",
"MaximumRetryCount": 0
,
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 1073741824,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": -1,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
,
"GraphDriver":
"Data":
"DeviceId": "119",
"DeviceName": "docker-254:0-354418880-9759c901ef5109a23a913840bd789fa6934ac18a4688ba60cabbad13b15078b8",
"DeviceSize": "10737418240"
,
"Name": "devicemapper"
,
"Mounts": [

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data",
"Destination": "/host/data",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files",
"Destination": "/host/files",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/data",
"Destination": "/data",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log",
"Destination": "/var/log",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"

],
"Config":
"Hostname": "provo-burlywood",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ZYPPER=zypper --no-gpg-checks --non-interactive",
"JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-oracle/",
"APPLICATION=fabric",
"ROLE=lifecycle",
"VERSION=3.3.0.0-3594.2b8e92d",
"DOCKER_FIX= "
],
"Cmd": [
"lifecycle"
],
"Image": "caspian/fabric:3.3.0.0-3594.2b8e92d",
"Volumes": null,
"WorkingDir": "/opt/emc/caspian/fabric/lifecycle",
"Entrypoint": [
"./boot.sh"
],
"OnBuild": null,
"Labels":
,
"NetworkSettings":
"Bridge": "",
"SandboxID": "683a8af8564b3083ac766b7065d5c84315ae8d2d0898c5099baccf2e137e7ca6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": ,
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks":
"host":
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "d8f7b03c732d5c57d170d76211c33710a17c8f670a5d8c9ebb91a0bdc2f8bb46",
"EndpointID": "ef788fd7eaa43369a184287c88ea19a7f5f369c808d3af40b9df41579a1251a6",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null




]


Expected output:



id, state, pid, exitCode, name, privileged, cmdLine, image = 'e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e;running;95168;0;fabric-lifecycle;false;[ "lifecycle" ];caspian/fabric:3.3.0.0-3594.2b8e92d;1073741824'.split(';)**









share|improve this question









New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 4




    Rather than executing an external shell command to do your substitution, this strikes me as something that Python should be able to do a lot quicker by itself.
    – Kusalananda
    Oct 4 at 12:11






  • 2




    I agree with @Kusalananda, python is taillored to parse input string for values and format an output string. You should make a new question in stackoverflow, please specifiy a sample input string (out value in your code) and an expected output (runcmd in your code).
    – Archemar
    Oct 4 at 12:34












up vote
0
down vote

favorite









up vote
0
down vote

favorite











command = '''out=$(%s);echo $out | sed -n 's/.*"Id": "(.*)", "Created".*"Status": "(.*)", "Running".*"Pid": (.*),.*"ExitCode": (.*), "Error".*"Name": "/(.*)", "RestartCount".*"Privileged": (.*), "PublishAllPorts".*"Cmd": (.*), "Image": "(.*)", "Volumes".*/1;2;3;4;5;6;7;8/p' ''' %out

runcmd = self.srv.execute(command)

received runcmd = ['x01;x02;x03;x04;x05;x06;x07;caspian/fabric-registry:2.3.1.0-58.3a6dfafn'] .


only 8thkey is correctly assigned ..Remaining all from 1 to 7 are not assigned with its value from out.Why is it so ?



Help would be much appreciated



where as out =
[

"Id": "e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e",
"Created": "2018-10-01T05:34:37.972705474Z",
"Path": "./boot.sh",
"Args": [
"lifecycle"
],
"State":
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 95168,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-10-01T05:34:51.739952918Z",
"FinishedAt": "2018-10-01T05:34:46.361850627Z"
,
"Image": "sha256:328eab472dbd625983c23f8760bc3d0b595dd161ee0d12e1d6d53c8b70228fd1",
"ResolvConfPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hostname",
"HostsPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hosts",
"LogPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e-json.log",
"Name": "/fabric-lifecycle",
"RestartCount": 0,
"Driver": "devicemapper",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig":
"Binds": [
"/opt/emc/caspian/fabric/agent/services/fabric/data:/data:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log:/var/log:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data:/host/data:ro",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files:/host/files:ro"
],
"ContainerIDFile": "",
"LogConfig":
"Type": "json-file",
"Config":
,
"NetworkMode": "host",
"PortBindings": null,
"RestartPolicy":
"Name": "",
"MaximumRetryCount": 0
,
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 1073741824,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": -1,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
,
"GraphDriver":
"Data":
"DeviceId": "119",
"DeviceName": "docker-254:0-354418880-9759c901ef5109a23a913840bd789fa6934ac18a4688ba60cabbad13b15078b8",
"DeviceSize": "10737418240"
,
"Name": "devicemapper"
,
"Mounts": [

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data",
"Destination": "/host/data",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files",
"Destination": "/host/files",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/data",
"Destination": "/data",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log",
"Destination": "/var/log",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"

],
"Config":
"Hostname": "provo-burlywood",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ZYPPER=zypper --no-gpg-checks --non-interactive",
"JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-oracle/",
"APPLICATION=fabric",
"ROLE=lifecycle",
"VERSION=3.3.0.0-3594.2b8e92d",
"DOCKER_FIX= "
],
"Cmd": [
"lifecycle"
],
"Image": "caspian/fabric:3.3.0.0-3594.2b8e92d",
"Volumes": null,
"WorkingDir": "/opt/emc/caspian/fabric/lifecycle",
"Entrypoint": [
"./boot.sh"
],
"OnBuild": null,
"Labels":
,
"NetworkSettings":
"Bridge": "",
"SandboxID": "683a8af8564b3083ac766b7065d5c84315ae8d2d0898c5099baccf2e137e7ca6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": ,
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks":
"host":
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "d8f7b03c732d5c57d170d76211c33710a17c8f670a5d8c9ebb91a0bdc2f8bb46",
"EndpointID": "ef788fd7eaa43369a184287c88ea19a7f5f369c808d3af40b9df41579a1251a6",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null




]


Expected output:



id, state, pid, exitCode, name, privileged, cmdLine, image = 'e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e;running;95168;0;fabric-lifecycle;false;[ "lifecycle" ];caspian/fabric:3.3.0.0-3594.2b8e92d;1073741824'.split(';)**









share|improve this question









New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











command = '''out=$(%s);echo $out | sed -n 's/.*"Id": "(.*)", "Created".*"Status": "(.*)", "Running".*"Pid": (.*),.*"ExitCode": (.*), "Error".*"Name": "/(.*)", "RestartCount".*"Privileged": (.*), "PublishAllPorts".*"Cmd": (.*), "Image": "(.*)", "Volumes".*/1;2;3;4;5;6;7;8/p' ''' %out

runcmd = self.srv.execute(command)

received runcmd = ['x01;x02;x03;x04;x05;x06;x07;caspian/fabric-registry:2.3.1.0-58.3a6dfafn'] .


only 8thkey is correctly assigned ..Remaining all from 1 to 7 are not assigned with its value from out.Why is it so ?



Help would be much appreciated



where as out =
[

"Id": "e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e",
"Created": "2018-10-01T05:34:37.972705474Z",
"Path": "./boot.sh",
"Args": [
"lifecycle"
],
"State":
"Status": "running",
"Running": true,
"Paused": false,
"Restarting": false,
"OOMKilled": false,
"Dead": false,
"Pid": 95168,
"ExitCode": 0,
"Error": "",
"StartedAt": "2018-10-01T05:34:51.739952918Z",
"FinishedAt": "2018-10-01T05:34:46.361850627Z"
,
"Image": "sha256:328eab472dbd625983c23f8760bc3d0b595dd161ee0d12e1d6d53c8b70228fd1",
"ResolvConfPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/resolv.conf",
"HostnamePath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hostname",
"HostsPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/hosts",
"LogPath": "/var/lib/docker/containers/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e/e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e-json.log",
"Name": "/fabric-lifecycle",
"RestartCount": 0,
"Driver": "devicemapper",
"Platform": "linux",
"MountLabel": "",
"ProcessLabel": "",
"AppArmorProfile": "docker-default",
"ExecIDs": null,
"HostConfig":
"Binds": [
"/opt/emc/caspian/fabric/agent/services/fabric/data:/data:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log:/var/log:rw",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data:/host/data:ro",
"/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files:/host/files:ro"
],
"ContainerIDFile": "",
"LogConfig":
"Type": "json-file",
"Config":
,
"NetworkMode": "host",
"PortBindings": null,
"RestartPolicy":
"Name": "",
"MaximumRetryCount": 0
,
"AutoRemove": false,
"VolumeDriver": "",
"VolumesFrom": null,
"CapAdd": null,
"CapDrop": null,
"Dns": null,
"DnsOptions": null,
"DnsSearch": null,
"ExtraHosts": null,
"GroupAdd": null,
"IpcMode": "shareable",
"Cgroup": "",
"Links": null,
"OomScoreAdj": 0,
"PidMode": "",
"Privileged": false,
"PublishAllPorts": false,
"ReadonlyRootfs": false,
"SecurityOpt": null,
"UTSMode": "",
"UsernsMode": "",
"ShmSize": 67108864,
"Runtime": "runc",
"ConsoleSize": [
0,
0
],
"Isolation": "",
"CpuShares": 0,
"Memory": 1073741824,
"NanoCpus": 0,
"CgroupParent": "",
"BlkioWeight": 0,
"BlkioWeightDevice": null,
"BlkioDeviceReadBps": null,
"BlkioDeviceWriteBps": null,
"BlkioDeviceReadIOps": null,
"BlkioDeviceWriteIOps": null,
"CpuPeriod": 0,
"CpuQuota": 0,
"CpuRealtimePeriod": 0,
"CpuRealtimeRuntime": 0,
"CpusetCpus": "",
"CpusetMems": "",
"Devices": null,
"DeviceCgroupRules": null,
"DiskQuota": 0,
"KernelMemory": 0,
"MemoryReservation": 0,
"MemorySwap": -1,
"MemorySwappiness": null,
"OomKillDisable": false,
"PidsLimit": 0,
"Ulimits": null,
"CpuCount": 0,
"CpuPercent": 0,
"IOMaximumIOps": 0,
"IOMaximumBandwidth": 0
,
"GraphDriver":
"Data":
"DeviceId": "119",
"DeviceName": "docker-254:0-354418880-9759c901ef5109a23a913840bd789fa6934ac18a4688ba60cabbad13b15078b8",
"DeviceSize": "10737418240"
,
"Name": "devicemapper"
,
"Mounts": [

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/data",
"Destination": "/host/data",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/host/files",
"Destination": "/host/files",
"Mode": "ro",
"RW": false,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/data",
"Destination": "/data",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"
,

"Type": "bind",
"Source": "/opt/emc/caspian/fabric/agent/services/fabric/lifecycle/log",
"Destination": "/var/log",
"Mode": "rw",
"RW": true,
"Propagation": "rprivate"

],
"Config":
"Hostname": "provo-burlywood",
"Domainname": "",
"User": "",
"AttachStdin": false,
"AttachStdout": false,
"AttachStderr": false,
"Tty": false,
"OpenStdin": false,
"StdinOnce": false,
"Env": [
"PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin",
"ZYPPER=zypper --no-gpg-checks --non-interactive",
"JAVA_HOME=/usr/lib64/jvm/jre-1.8.0-oracle/",
"APPLICATION=fabric",
"ROLE=lifecycle",
"VERSION=3.3.0.0-3594.2b8e92d",
"DOCKER_FIX= "
],
"Cmd": [
"lifecycle"
],
"Image": "caspian/fabric:3.3.0.0-3594.2b8e92d",
"Volumes": null,
"WorkingDir": "/opt/emc/caspian/fabric/lifecycle",
"Entrypoint": [
"./boot.sh"
],
"OnBuild": null,
"Labels":
,
"NetworkSettings":
"Bridge": "",
"SandboxID": "683a8af8564b3083ac766b7065d5c84315ae8d2d0898c5099baccf2e137e7ca6",
"HairpinMode": false,
"LinkLocalIPv6Address": "",
"LinkLocalIPv6PrefixLen": 0,
"Ports": ,
"SandboxKey": "/var/run/docker/netns/default",
"SecondaryIPAddresses": null,
"SecondaryIPv6Addresses": null,
"EndpointID": "",
"Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"MacAddress": "",
"Networks":
"host":
"IPAMConfig": null,
"Links": null,
"Aliases": null,
"NetworkID": "d8f7b03c732d5c57d170d76211c33710a17c8f670a5d8c9ebb91a0bdc2f8bb46",
"EndpointID": "ef788fd7eaa43369a184287c88ea19a7f5f369c808d3af40b9df41579a1251a6",
"Gateway": "",
"IPAddress": "",
"IPPrefixLen": 0,
"IPv6Gateway": "",
"GlobalIPv6Address": "",
"GlobalIPv6PrefixLen": 0,
"MacAddress": "",
"DriverOpts": null




]


Expected output:



id, state, pid, exitCode, name, privileged, cmdLine, image = 'e5330efcb429bab6bb31571fb878d0cd3a7078c537bd9606360a05886e55f72e;running;95168;0;fabric-lifecycle;false;[ "lifecycle" ];caspian/fabric:3.3.0.0-3594.2b8e92d;1073741824'.split(';)**






sed python






share|improve this question









New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited Oct 4 at 14:05









Philippos

5,96711546




5,96711546






New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked Oct 4 at 12:03









Kalapriya Pasupuleti

11




11




New contributor




Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






Kalapriya Pasupuleti is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 4




    Rather than executing an external shell command to do your substitution, this strikes me as something that Python should be able to do a lot quicker by itself.
    – Kusalananda
    Oct 4 at 12:11






  • 2




    I agree with @Kusalananda, python is taillored to parse input string for values and format an output string. You should make a new question in stackoverflow, please specifiy a sample input string (out value in your code) and an expected output (runcmd in your code).
    – Archemar
    Oct 4 at 12:34












  • 4




    Rather than executing an external shell command to do your substitution, this strikes me as something that Python should be able to do a lot quicker by itself.
    – Kusalananda
    Oct 4 at 12:11






  • 2




    I agree with @Kusalananda, python is taillored to parse input string for values and format an output string. You should make a new question in stackoverflow, please specifiy a sample input string (out value in your code) and an expected output (runcmd in your code).
    – Archemar
    Oct 4 at 12:34







4




4




Rather than executing an external shell command to do your substitution, this strikes me as something that Python should be able to do a lot quicker by itself.
– Kusalananda
Oct 4 at 12:11




Rather than executing an external shell command to do your substitution, this strikes me as something that Python should be able to do a lot quicker by itself.
– Kusalananda
Oct 4 at 12:11




2




2




I agree with @Kusalananda, python is taillored to parse input string for values and format an output string. You should make a new question in stackoverflow, please specifiy a sample input string (out value in your code) and an expected output (runcmd in your code).
– Archemar
Oct 4 at 12:34




I agree with @Kusalananda, python is taillored to parse input string for values and format an output string. You should make a new question in stackoverflow, please specifiy a sample input string (out value in your code) and an expected output (runcmd in your code).
– Archemar
Oct 4 at 12:34















active

oldest

votes











Your Answer







StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: false,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);






Kalapriya Pasupuleti is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473216%2fsed-command-execution-in-python%23new-answer', 'question_page');

);

Post as a guest



































active

oldest

votes













active

oldest

votes









active

oldest

votes






active

oldest

votes








Kalapriya Pasupuleti is a new contributor. Be nice, and check out our Code of Conduct.









 

draft saved


draft discarded


















Kalapriya Pasupuleti is a new contributor. Be nice, and check out our Code of Conduct.












Kalapriya Pasupuleti is a new contributor. Be nice, and check out our Code of Conduct.











Kalapriya Pasupuleti is a new contributor. Be nice, and check out our Code of Conduct.













 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f473216%2fsed-command-execution-in-python%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

How to check contact read email or not when send email to Individual?

Bahrain

Postfix configuration issue with fips on centos 7; mailgun relay