Convert Tabular Cli Output To Json Format In Python Stack Overflow

Convert Tabular Cli Output To Json Format In Python Stack Overflow Assume your entire output is in text. import re lines = text.split("\n") keylines = [line for i, line in enumerate(lines) if len(lines)>(i 1) and " " in lines[i 1]] vallines = [line for i, line in enumerate(lines) if i!=0 and " " in lines[i 1]] keys = re.split(" ", " ".join(keylines)) vals = re.split(" ", " ".join(vallines)). Cli tool and python library that converts the output of popular command line tools, file types, and common strings to json, yaml, or dictionaries. this allows piping of output to tools like jq and simplifying automation scripts.

Convert Tabular Cli Output To Json Format In Python Stack Overflow 3 with plain bash you could do: json=$( sh macscript.sh | { pairs=() while read interface; read ether; do pairs =("\"$interface\":\"$ether\"") done ifs=, echo "{${pairs[*]}}" } ) echo "$json" outputs {"eth0":"11:1d:11:11:11:1d","lo":"00:00:00:00:00:00"}.

Converting Nested Json Into Tabular Format Using Python Stack Overflow
Comments are closed.