是否可以在不安装任何库的情况下将任何Linux命令的输出格式化为JSON?
我还想知道如何将任何Linux命令格式化为以逗号/管道分隔的字符串。
我正在使用Debain(Jessie),但该软件无关紧要。
以下是我想格式化的命令示例:
命令:ls
bin etc lib media proc sbin tmp vmi95300
boot home lib64 mnt root srv usr vmlinuz
dev initrd.img lost+found opt run sys var
收件人(逗号或管道):
bin|etc|lib|media|proc|sbin|tmp|vmi95300|boot|home|lib64|mnt|root|srv|usr|vmlinuz|dev|initrd.img|lost+found|opt|run|sys|var
甚至更好(JSON):
[bin,etc,lib,media,proc,sbin,tmp,vmi95300,boot,home,lib64,mnt,root,srv,usr,vmlinuz,dev,initrd.img,lost+found,opt,run,sys,var]
命令:cat / etc / * release
PRETTY_NAME="Debian GNU/Linux 8 (jessie)"
NAME="Debian GNU/Linux"
VERSION_ID="8"
VERSION="8 (jessie)"
ID=debian
HOME_URL="http://www.debian.org/"
SUPPORT_URL="http://www.debian.org/support"
BUG_REPORT_URL="https://bugs.debian.org/"
收件人:
{
"PRETTY_NAME": "\"Debian GNU/Linux 8 (jessie)\"",
"NAME": "\"Debian GNU/Linux\"",
"VERSION_ID": "\"8\"",
"VERSION": "\"8 (jessie)\"",
"ID": "debian",
"HOME_URL": "\"http://www.debian.org/\"",
"SUPPORT_URL": "\"http://www.debian.org/support\"",
"BUG_REPORT_URL": "\"https://bugs.debian.org/\""
}