A general purpose application and library for aligning text.

align

A general purpose application that aligns text

GoDoc Build Status Go Report Card Coverage Status

The focus of this application is to provide a fast, efficient, and useful tool for aligning text. Its creation is the result of inspiration from several other amazing alignment tools, namely column or the Sublime Text plugin AlignTab.

See the Wiki for usage examples!

Included

  • A simple yet useful CLI with options to specify your delimiter, input and output files, etc.
  • Align by any string as your delimiter or separator, not just a single character.
  • If your separator string is contained within the data itself, it can be escaped by specifying a text qualifier.
  • Right, Center, or Left justification of each field.

Why?

Sometimes, it's just easier to align a CSV (or delimited file) by its delimiter and view the columns in your plain text editor (which saves you from opening Excel!).

Another use is to align blocks of code by = or =>, etc.

Install

$ go get github.com/Guitarbum722/align
$ make install

$ # build all binaries
$ make release

Usage - CLI examples

Usage: align [-h] [-f] [-o] [-q] [-s] [-d] [-a] [-c] [-i] [-p]
Options:
  -h | --help  help
  -f           input file.  If not specified, pipe input to stdin
  -o           output file. (default: stdout)
  -q           text qualifier (if applicable)
  -s           delimiter (default: ',')
  -d           output delimiter (defaults to the value of sep)
  -a           <left>, <right>, <center> justification (default: left)
  -c           output specific fields (default: all fields)
  -i           override justification by column number (e.g. 2:center,5:right)
  -p           extra padding surrounding delimiter

Specify your input file, output file, delimiter. You can also pipe input to stdin (if the -f option is provided, it will take precedence over Stdin) If no -o option is provided, stdout will be used.

$ align -f input_file.csv -o output_file.csv

$ align -f input_file.csv -o 

$ cat awesome.csv | align

Do you have rows with a different number of fields? This might be more common with code, but align doesn't care!

$ echo "field1|field2\nValue1|Value2\nCoolValue1|CoolValue2|CoolValue3" | align -s \|
field1     | field2
Value1     | Value2
CoolValue1 | CoolValue2 | CoolValue3

Column filtering (specifiy output fields and optionally override the justification of the output fields). This might be useful if you would like to display a dollar amount or number field differently. The specified fields are indexed at 1.

# output fields 1,3,5 justified 'right'
$ cat file.csv | align -a right -c 1,3,5

# output fields 1,2,3,7,8 with default justification (left) except for field 7, which is right justified
$ cat file.csv | align -c 1,2,3,7,8 -i 1:right,7:center

#output all fields by default, with right justification, with overridden justification on certain columns
$ cat file.csv | align -a right -i 1:center,5:left

Support for worldwide characters.

first          , last              , middle  , email
paul           , danny             ,  かど    , や製油

It is perfectly acceptable to even use emojis as your input/output delimiters.

first  😮 last     😮 email
Hector 😮 Gonzalez 😮 [email protected]

Add additional padding if desired with the -p flag. Default is 1 space, and 0 will output with no additional padding. If the value supplied is less than 0, then the behavior will be as if it were set to 0 and no padding will be applied.

# padding of 4 spaces surrounding the delimiter.
align -p 4

Contributions

If you have suggestions or discover a bug, please open an issue. If you think you can make the fix, please use the Fork / Pull Request on your feature branch approach.

Comments
  • Issue39 alignment

    Issue39 alignment

    This resolves #39 (sort of).

    Instead of a flag that switches the justification of a numeric field (and correctly detecting the numeric field) I added a -v flag. This allows the user to set column overrides for the justification for any field that they specify. This example aligns all fields to the right, but aligns the specified fields differently with the argument to -v:

    align -f input.csv -a right -v 1-left,5-center

    • adding a map to the PaddingOpts struct which will get checked in the export() function.
    • updating README with usage, and examples
    • updating tests
  • Configurable padding

    Configurable padding

    Closes #30

    • add -p flag to specify number of spaces to pad each column around the separator/delimiter
    • consumer of the lib can set Surround on Align.PaddingOpts.
    • default is 1 space for padding, which is the current behavior anyway.

    Since the other features in #30 are either out of scope or covered by the current justification features, we will wait to see if any use cases present themselves for additional functionality.

  • Commas Between Quotes Seem to Be Used as Delimeters

    Commas Between Quotes Seem to Be Used as Delimeters

    45862 | 12515 | "Midwest Electric                        |  Inc"        | OH           | Bundled               | Cooperative           | 0.0915350239036  | 0.0777018476335 | 0.113463086111
    
  • Issue72 transposed columns

    Issue72 transposed columns

    Refactors an unexported function that counts the length of each field accordingly.

    This function also benchmarked at about 10.1 ns/op from 33.2 ns/op on my particular machine after refactor.

    Resolves #72

  • latest release binary giving error output

    latest release binary giving error output

    v1.1.1 is running well on my Arch Linux machine.

    latest release binary is giving error output as below :

    align-linux: line 1: syntax error near unexpected token `newline'
    align-linux: line 1: `!<arch>'
    
  • Issue67 reduce allocs

    Issue67 reduce allocs

    Resolves #67

    Refactors a fair amount of the export() function to reduce some allocations.
    Running the same benchmark mentioned in #67, the allocs were reduced from 17 to 8.

  • [enhancement] Options: space around delimiter

    [enhancement] Options: space around delimiter

    Spacing Options

    • [ ] space around
    • [ ] leading space
    • [ ] trailing space
    • [ ] initial leading space
    • [ ] final trailing space

    To consider the spacing option, let's use the following input:

    | Prop | Type | Default | Description |
    | :-------: | :-------: | :-------: | ------- |
    | tag | String    | `"div"`   | Element tagName _(any valid HTML tag name)_ |
    | inline   | Boolean   | `false`   | `display: inline-flex` |
    

    Space Around

    Space around would specify the minimum amount of white-space to add before and after a delimiter. In this shortcut option, initial leading space and final trailing space would not be included.

    // space around: 1
    | Prop      | Type      | Default   | Description |
    | :-------: | :-------: | :-------: |   -------   |
    | tag       | String    | `"div"`   | Element tagName _(any valid HTML tag name)_ |
    | inline    | Boolean   | `false`   | `display: inline-flex` |
    

    Leading Space

    Leading space would only specify the minimum amount of space immediately following a delimiter, excepting an initial delimiter not preceded by content.

    // leading space: 1
    | Prop     | Type     | Default  | Description|
    | :-------:| :-------:| :-------:|   -------  |
    | tag      | String   | `"div"`  | Element tagName _(any valid HTML tag name)_|
    | inline   | Boolean  | `false`  | `display: inline-flex`|
    

    Trailing Space

    Trailing space would only specify the minimum amount of space immediately preceding a delimiter, excepting one that is not followed by content.

    // trailing space: 1
    |Prop      |Type      |Default   |Description |
    |:-------: |:-------: |:-------: |  -------   |
    |tag       |String    |`"div"`   |Element tagName _(any valid HTML tag name)_ |
    |inline    |Boolean   |`false`   |`display: inline-flex` |
    

    Initial Leading Space

    Specify an amount of space to place before all content

    Final Trailing Space

    Specify an amount of space to place after all content

  • Last column in row empty if empty

    Last column in row empty if empty

    If the last field (column) in the input is null, then the last column is completely omitted from the output. In other words, the final delimiter does not appear in the row in the output.

    This does not occur if the last column contains an empty quoted string.

    Sample input:

    first,last,email,address,title,phone
    john,doe,[email protected],123 Any St.,Lord of Scrum,111-111-1111
    jane,doe,[email protected],123 Any Street,,222-222-2222
    tim,biziboi,[email protected],222 W. Avenue 3,"Director, Sr.",333-333-3333
    ,,,,,444-444-4444
    ,,,"222 3rd Ave., Apt. 4",,
    ,,,"222 3rd Ave., Apt. 4",,""
    ,,,,,
    ,,,,,555-555-5555
    ,,,,"Level 3,,, Manager",
    grogu,,[email protected],?,"Formerly known as, baby yoda",
    
    

    Result:

    first , last    , email                , address                , title                          , phone        
    john  , doe     , [email protected] , 123 Any St.            , Lord of Scrum                  , 111-111-1111 
    jane  , doe     , [email protected]  , 123 Any Street         ,                                , 222-222-2222 
    tim   , biziboi , [email protected] , 222 W. Avenue 3        , "Director, Sr."                , 333-333-3333 
          ,         ,                      ,                        ,                                , 444-444-4444 
          ,         ,                      , "222 3rd Ave., Apt. 4" ,                                
          ,         ,                      , "222 3rd Ave., Apt. 4" ,                                , ""           
          ,         ,                      ,                        ,                                
          ,         ,                      ,                        ,                                , 555-555-5555 
          ,         ,                      ,                        , "Level 3,,, Manager"           
    grogu ,         , [email protected]      , ?                      , "Formerly known as, baby yoda" 
    
    
  • Minor updates

    Minor updates

    • starts valid Justifications at 1
    • updates .gitignore
    • removes superfluous case for left justification when that is the default
    • removes an unused interface and references to it in commentary
  • Add option for column filtering

    Add option for column filtering

    This enhancement closes #48 .

    • -c flag added, which should be followed by a comma separated list of integers as the argument.
    • List consists of the desired field numbers expected in the output.
    • Indexing for the list starts at 1. Any number in the list less than 1 will also be ignored.
    • The list can be provided in any order, however the fields will still be output in the order in which they appear in the input (it might be cool to specify the order of the output fields, but that will have to be later).
    • If a number in the list is larger than the number of fields in the row, it will be ignored.
    • There will be no leading padding on the first field WRITTEN instead of the first field from the input (this avoids leading padding if the first field is excluded from the filter list)
  • parse command line flags with standard lib

    parse command line flags with standard lib

    Fixes #43 .

    • Remove vendored dependency
    • Parse command line args with standard flag package
      • Reassign flag.Usage to print the standard usage of the application
AppGo is an application that is intended to read a plain text log file and deliver an encoded polyline

AppGo AppGo is an application that is intended to read a plain text log file and deliver an encoded polyline. Installation To run AppGo it is necessar

Oct 23, 2021
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.
omniparser: a native Golang ETL streaming parser and transform library for CSV, JSON, XML, EDI, text, etc.

omniparser Omniparser is a native Golang ETL parser that ingests input data of various formats (CSV, txt, fixed length/width, XML, EDI/X12/EDIFACT, JS

Jan 4, 2023
:book: A Golang library for text processing, including tokenization, part-of-speech tagging, and named-entity extraction.

prose prose is a natural language processing library (English only, at the moment) in pure Go. It supports tokenization, segmentation, part-of-speech

Jan 4, 2023
👄 The most accurate natural language detection library in the Go ecosystem, suitable for long and short text alike
👄 The most accurate natural language detection library in the Go ecosystem, suitable for long and short text alike

?? The most accurate natural language detection library in the Go ecosystem, suitable for long and short text alike

Dec 25, 2022
A modern text indexing library for go
A modern text indexing library for go

bleve modern text indexing in go - blevesearch.com Features Index any go data structure (including JSON) Intelligent defaults backed up by powerful co

Jan 4, 2023
Fonetic is a library to assess pronounceablility of a given text

fonetic-go assess pronounciblity of text Introduction Fonetic is a library to assess pronounceablility of a given text. For more information, check ou

Oct 21, 2022
Parse placeholder and wildcard text commands

allot allot is a small Golang library to match and parse commands with pre-defined strings. For example use allot to define a list of commands your CL

Nov 24, 2022
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.
Produces a set of tags from given source. Source can be either an HTML page, Markdown document or a plain text. Supports English, Russian, Chinese, Hindi, Spanish, Arabic, Japanese, German, Hebrew, French and Korean languages.

Tagify Gets STDIN, file or HTTP address as an input and returns a list of most popular words ordered by popularity as an output. More info about what

Dec 19, 2022
Templating system for HTML and other text documents - go implementation

FAQ What is Kasia.go? Kasia.go is a Go implementation of the Kasia templating system. Kasia is primarily designed for HTML, but you can use it for any

Mar 15, 2022
Small and fast FTS (full text search)

Microfts A small full text indexing and search tool focusing on speed and space. Initial tests seem to indicate that the database takes about twice as

Jul 30, 2022
Diff, match and patch text in Go

go-diff go-diff offers algorithms to perform operations required for synchronizing plain text: Compare two texts and return their differences. Perform

Dec 25, 2022
PipeIt is a text transformation, conversion, cleansing and extraction tool.
PipeIt is a text transformation, conversion, cleansing and extraction tool.

PipeIt PipeIt is a text transformation, conversion, cleansing and extraction tool. Features Split - split text to text array by given separator. Regex

Aug 15, 2022
ByNom is a Go package for parsing byte sequences, suitable for parsing text and binary data

ByNom is a Go package for parsing byte sequences. Its goal is to provide tools to build safe byte parsers without compromising the speed or memo

May 5, 2021
Fast and secure steganography CLI for hiding text/files in images.
Fast and secure steganography CLI for hiding text/files in images.

indie CLI This complete README is hidden in the target.png file below without the original readme.png this could have also been a lie as none could ev

Mar 20, 2022
a simple and lightweight terminal text editor written in Go

Simple Text editor written in Golang build go build main.go

Oct 4, 2021
A UTF-8 and internationalisation testing utility for text rendering.

ɱéťàł "English, but metal" Metal is a tool that converts English text into a legible, Zalgo-like character swap for the purposes of testing localisati

Jan 1, 2023
A simple action that looks for multiple regex matches, in a input text, and returns the key of the first found match.

Key Match Action A simple action that looks for multiple regex matches, in a input text, and returns the key of the first found match. TO RUN Add the

Aug 4, 2022
Guess the natural language of a text in Go

guesslanguage This is a Go version of python guess-language. guesslanguage provides a simple way to detect the natural language of unicode string and

Dec 26, 2022
Extract urls from text

xurls Extract urls from text using regular expressions. Requires Go 1.13 or later. import "mvdan.cc/xurls/v2" func main() { rxRelaxed := xurls.Relax

Jan 7, 2023