GithubHelp home page GithubHelp logo

noborus / guesswidth Goto Github PK

View Code? Open in Web Editor NEW
26.0 2.0 0.0 164 KB

Guess the width (fwf) output without delimiters in commands that output to the terminal.

License: MIT License

Go 97.35% Makefile 2.65%
fixed-width fwf

guesswidth's Introduction

guesswidth

Go Reference Go

Overview

guesswidth guesses the column position for fixed-width formats(fwf).

The output of the ps command has no delimiters, making the values difficult to machine-readable. guesswidth guesses smarter than just space delimiters.

guesswidth is guessed based on the position of characters in the header. So having a header will give you better results.

Install command

There is also a guesswidth command.

go install github.com/noborus/guesswidth/cmd/guesswidth@latest

Guess the width output with no delimiters in the command.

$ ps
    PID TTY          TIME CMD
 302965 pts/3    00:00:12 zsh
 733211 pts/3    00:00:00 ps
 733212 pts/3    00:00:00 tee
 733213 pts/3    00:00:00 guesswidth

Split the output like this:

$ ps | guesswidth
    PID| TTY     |     TIME|CMD
 302965| pts/3   | 00:00:08|zsh
 539529| pts/3   | 00:00:00|ps
 539530| pts/3   | 00:00:00|guesswidth

It can be converted to csv.

$ ps | guesswidth csv
PID,TTY,TIME,CMD
302965,pts/3,00:00:12,zsh
733211,pts/3,00:00:00,ps
733212,pts/3,00:00:00,tee
733213,pts/3,00:00:00,guesswidth
ps | guesswidth --align
   PID|TTY  |    TIME|CMD
302965|pts/3|00:00:12|zsh
733211|pts/3|00:00:00|ps
733212|pts/3|00:00:00|tee
733213|pts/3|00:00:00|guesswidth

Usage

$ guesswidth -h         [~/dev/src/github.com/noborus/guesswidth]
Guess the width of the columns from the header and body,
split them, insert fences and output.

Usage:
  guesswidth [flags]
  guesswidth [command]

Available Commands:
  completion  Generate the autocompletion script for the specified shell
  csv         Output in csv format
  help        Help about any command

Flags:
  -a, --align          align the output
      --fence string   fence (default "|")
      --header int     header line number (default 1)
  -h, --help           help for guesswidth
      --scannum int    number of line to scan (default 100)
      --split int      maximum number of splits (default -1)
  -v, --version        version for guesswidth

Use "guesswidth [command] --help" for more information about a command.

Examples

guesswidth inserts a delimiter (| by default) (Colors are changed here for clarity).

Even if there are spaces in the header or body, they will be separated correctly.

ps

ps

docker ps

docker-ps

docker node

docker node ls

guesswidth's People

Contributors

noborus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  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.