Skip to content

namshi/node-shell-parser

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

From shell output to json

Converts the usual, space separated, table from a shell command into a list of json object where the keys are the columns' names and the values the different data for each row.

Install

You can install this library through NPM:

npm install node-shell-parser

Definition:

  shellParser(shellOutput, options);
  • shellOutput: the string resulting from running your command
  • options.separator: which character separates your tabled data, default is one space
  • options.skipLines: how many lines to skip before meeting the columns definition header

Usage

Execute a process, get its output and then simply feed it to the parser:

var shellParser = require('node-shell-parser');
var child = require('child_process');

var process = child.spawn('ps');
var shellOutput = '';

process.stdout.on('data', function (chunk) {
  shellOutput += chunk;
});

process.stdout.on('end', function () {
  console.log(shellParser(shellOutput))
});

Black magic in action:

~/projects/namshi/node-shell-parser (master ✘)✭ ᐅ node test.js
[ { PID: '729', TTY: 'pts/1    00:0', TIME: '0:00', CMD: 'zsh' },
  { PID: '057', TTY: 'pts/1    00:0', TIME: '0:00', CMD: 'node' },
  { PID: '059', TTY: 'pts/1    00:0', TIME: '0:00', CMD: 'ps' } ]

About

Parse commands like `ps -aux`, then relax.

Resources

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •