Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert TXT to CSV
#1
Hello,

I need help converting a text file, to a CSV that I could use in splunk.

This is my source file:

Image Digest: sha256:316ebb92ca66bb8ddc79249fb29872bece4be384cb61b5344fac4e84ca4ed2b2
Full Tag: docker.io/debian:latest
Image ID: 2b98c9851a37e18356abe407922726dc35c370f7cee76f435f94ee92950b4493
Status: fail
Last Eval: 2018-03-29T07:39:35
Policy ID: 94a030d0-241f-4ad9-8ef6-a74ee8d2aa42

Gate Trigger Detail Status
anchoresec vulnhigh HIGH Vulnerability found in package - libblkid1 (CVE-2016-2779 - https://security-tracker.debian.org/trac...-2016-2779) stop
anchoresec vulnhigh HIGH Vulnerability found in package - libc6 (CVE-2017-8804 - https://security-tracker.debian.org/trac...-2017-8804) stop
anchoresec vulnhigh HIGH Vulnerability found in package - libc6 (CVE-2018-1000001 - https://security-tracker.debian.org/trac...18-1000001) stop

So I would like to keep only the four columns (gate, trigger, detail, status), the TullTag entry as a title, and convert it to CSV (commas and quotation marks for the details column)

How can I proceed in python to get a CSV from the above file?

I don't know if it's any easier butI can also get the source file in json form, but I do have useless information to sort. This is an example:

"result": {
"2b98c9851a37e18356abe407922726dc35c370f7cee76f435f94ee92950b4493": {
"result": {
"final_action": "STOP",
"header": [
"Image_Id",
"Repo_Tag",
"Trigger_Id",
"Gate",
"Trigger",
"Check_Output",
"Gate_Action",
"Whitelisted"
],
"row_count": 29,
"rows": [
[
"2b98c9851a37e18356abe407922726dc35c370f7cee76f435f94ee92950b4493",
"docker.io/debian:latest",
"CVE-2016-2779+libblkid1",
"anchoresec",
"vulnhigh",
"HIGH Vulnerability found in package - libblkid1 (CVE-2016-2779 - https://security-tracker.debian.org/trac...-2016-2779)",
"stop",
false
],
[
"2b98c9851a37e18356abe407922726dc35c370f7cee76f435f94ee92950b4493",
"docker.io/debian:latest",
"CVE-2017-8804+libc6",
"anchoresec",
"vulnhigh",
"HIGH Vulnerability found in package - libc6 (CVE-2017-8804 - https://security-tracker.debian.org/trac...-2017-8804)",
"stop",
false
]

Thank you in advance.

Sincerely. Smile
Reply


Messages In This Thread
Convert TXT to CSV - by jabberwock88 - Mar-29-2018, 08:14 AM
RE: Convert TXT to CSV - by buran - Mar-29-2018, 08:21 AM

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020