Giter Club home page Giter Club logo

table-parser's Introduction

Table Parser

A parser to parse table style output from shell

This project was forked to slim down the prod dependencies

Install

You can include it your package.json file as follows:

"table-parser": "nicolaspearson/table-parser"

Usage

We have some kind of log below as test/ps.log:

  PID TTY           TIME CMD
49692 ttys000    0:00.06 login -pfl local /bin/bash -c exec -la bash /bin/bash
49693 ttys000    0:00.06 -bash
54195 ttys000    0:00.09 node run

...

56266 ttys005    0:00.06 login -pfl local /bin/bash -c exec -la bash /bin/bash
56269 ttys005    0:00.04 -bash
56463 ttys005    0:00.09 node test.js
56464 ttys005    0:00.01 ps -a

Use table-parser to parse it into object:

var fs = require( 'fs' );
var Parser = require('table-parser');

var linux_ps = './ps.log';

data = fs.readFileSync( linux_ps ).toString();
var parsedData = Parser.parse( data );

console.log( parsedData );

Which will output:

[ { PID: [ '49692' ],
    TTY: [ 'ttys000' ],
    TIME: [ '0:00.06' ],
    CMD:
     [ 'login',
       '-pfl',
       'local',
       '/bin/bash',
       '-c',
       'exec',
       '-la',
       'bash',
       '/bin/bash' ] },
  ...

  { PID: [ '56464' ],
    TTY: [ 'ttys005' ],
    TIME: [ '0:00.01' ],
    CMD: [ 'ps', '-a' ] } ]

Double quotation marks

Normally, all the values will be transformed into array using split( /\s+/ ), but string wrapped with " will be treated as a continuous string.

For example, the CommandLine below:

"C:\Program Files\Internet Explorer\iexplore.exe" --name="Local" --type=parse

will be split into:

  • C:\Program Files\Internet Explorer\iexplore.exe ( " will be removed, if " is at the beginning )
  • --name="Local" ( " is reserved )
  • --type=parse

table-parser's People

Contributors

neekey avatar empact avatar kingio avatar nicolaspearson avatar semantic-release-bot avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.