Skip to content

fw1121/structured-text-tools

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 

Repository files navigation

Structured text tools

The following is a list of text-based file formats and command line tools for manipulating each.

Contents

DSV

Delimiter-separated values, including CSV, TSV, etc.

Awk

Awk is a POSIX-standard command line tool and programming language for processing DSV data. If you use Linux, macOS or a BSD, you almost certainly have it installed. See below for Windows.

  • If you already know how to program, the nawk man page is a great way to learn Awk quickly. What you learn from it will apply to other implementations on different platforms. Read it first if you feel overwhelmed by the sheer size of the GNU Awk manual.
  • Awk.info archive — an extensive resource on Awk.
  • AWK Vs NAWK Vs GAWK — a comparison of implementations' features.
  • busybox-w32 includes a full implementation of POSIX Awk and other tools like sed in a single Windows executable.

POSIX commands

Name Description
cut Select portions of each line in one or several files. Can work with delimiter-separated fields. (Manual: man 1 cut on your system, GNU, FreeBSD.)
grep Select lines from one or several files. (Manual: man 1 grep, GNU, FreeBSD.)
join Join the lines from two files on a common field. (Manual: man 1 join, GNU, FreeBSD.)
paste Combine several consecutive lines in a text file into one. (Manual: man 1 paste, GNU, FreeBSD.)
sort Sort lines by key fields. (Manual: man 1 sort, GNU, FreeBSD.)
uniq Find or remove repeated lines. (Manual: man 1 uniq, GNU, FreeBSD.)

Other tools

Name and link Description
csv2md Convert CSV to Markdown tables.
csv2html Convert CSV to HTML tables.
csvfaker Generate CSV files with fake data. Supports different types of fake data in different locales: names, cities, jobs, email addresses, and others.
csvfix A multitool. Compare, filter, normalize, split, and validate CSV files. Reorder, remove, split, and merge fields. Convert data between fixed-width, multi-line, XML, and DSV format. Generate SQL statements. Documentation.
GNU datamash Perform statistical operations on text input.
jp (sgreben) Plot data. See the JSON section.
Miller sed, awk, cut, join and sort for name-indexed data such as CSV and tabular JSON.
rows A Python library with a CLI. Convert between a number of file formats for tabular data: CSV, XLS, XLSX, ODS, and others. Query the data (via SQLite). Combine tables. Generate schemas.
tab A non-Turing-complete statically typed programming language for data processing. An alternative to Awk.
eBay's TSV utilities Filter, summarize, join, and perform other operations on TSV files. Written in D.
xsv Index, slice, analyze, split, and join CSV files.

SQL-based utilities

Name and link Programming language and database engine Features Usage link License
csvkit Python, SQLite 3 Use header row for column names. Custom input and output encoding. Custom input field separator. Custom output field separator. Custom output formatting. CSV JOINs. Python module. Excel and JSON to CSV. CSV to JSON. SQL queries for CSV. Usage MIT
fsql Perl, custom SQL interpreter CSV, TSV, LTSV, Perl, JSON, and YAML input and output. Table JOINs. Custom SQL functions defined in Perl. Array and dictionary output for Perl, JSON, and YAML. Usage Choice of GNU GPLv1+ or Artistic License
q Python, SQLite 3 Use header row for column names. Custom input and output encoding. Gzipped input. Custom input field separator (string literal). Custom output field separator. Custom output formatting. Table JOINs. Python module. Usage GNU GPLv3
rows Python, SQLite 3 See the Other tools section. Usage GNU LGPLv3
Sqawk Tcl, SQLite 3 Use header row for column names. Custom input field separator (regexp, per-file). Custom input record delimiter (regexp, per-file). Custom output field separator. Custom output record separator. Custom table names. Merge selected columns into one. Skip columns. ASCII/Unicode table output, CSV input and output. JSON output. Keep SQLite file. Tcl input and output. Table JOINs. Usage MIT
sqawk C, SQLite 3 Use header row for column names. Column name aliases. Can skip lines until a regexp matches. Custom input field separator (string literal, per-file). Keep SQLite file. Show generated SQL. Table JOINs. Usage ?
Squawk Python, custom SQL interpreter Access log and CSV input. JSON and CSV output. Python code generation. Three-clause BSD
termsql Python, SQLite 3 Use header rows for column names. Custom field separator (regexp). Custom record separator (string literal). Lines as columns. Skip a given number of lines and the beginning and at the end. Merge selected columns into one. HTML, CSV, SQL, and Tcl output. Manual MIT
trdsql Go, MySQL/PostgreSQL/SQLite 3 Use header row for column names. Custom field separator (string literal). Table JOINs. CSV, LTSV, and JSON input. CSV, LTSV, JSON, ASCII table, Markdown output. Usage MIT
textql Go, SQLite 3 Use header rows for column names. Keep SQLite file. Custom input field separator (string literal). Usage MIT

XML, HTML

Name and link Description
xml-to-json-fast Convert XML to JSON. Can handle very large XML files.
html-xml-utils A number of simple utilities (like hxcopy, hxpipe, hxunent, hxselect) for manipulating HTML and XML files from W3C. Written in C, quite old-fashioned, but still relevant and maintained.
pup Query HTML pages with CSS selectors. Static binaries available for releases. Inspired by jq.
Saxon Query XML and HTML data with XPath. Documentation.
Temme Query HTML with CSS-like selectors to extract JSON. Temme extends CSS selectors with value capture patterns.
tq Query HTML with CSS selectors.
Xidel Query or modify XML and HTML pages with XPath, XQuery 3, and CSS selectors.
xml2 Convert XML and HTML to and from flat, greppable lists of "path=value" statements. Source code mirror.
XMLLint Query (including XSLT), validate and reformat XML documents.
XMLStarlet Query, modify, and validate XML documents.
xq jq wrapper for XML documents.

See also: Grep and Sed Equivalent for XML Command Line Processing on StackOverflow.

JSON

Name and link Description
fx Run arbitrary JavaScript on JSON input. Standalone binaries available.
gron Convert JSON to and from flat, greppable lists of "path=value" statements.
jiq Drill down JSON interactively by using filtering queries like jq.
jl Query and manipulate JSON using a tiny functional language.
jo Create JSON objects from the shell.
jp (jmespath) JMESPath
jp (sgreben) Plot JSON and CSV data in the terminal. Supports different kinds of plots: bar charts, line charts, scatter plots, histograms, and heatmaps.
jq Create and manipulate JSON with a functional (as in "functional programming") DSL. Can convert JSON to other formats.
jshon Create and manipulate JSON using getopt-style command-line options.
json2 Convert JSON to and from flat, greppable lists of "path=value" statements. Modeled after xml2.
jsonaxe Create and manipulate JSON with a Python-based DSL. Inspired by jq.
json Run arbitrary JavaScript on JSON input.
json-table Convert nested JSON into CSV or TSV for processing in the shell.
json.tool (Python 3 docs) Validate and pretty-print JSON. This module is part of the standard library of Python 2/3 and is likely to be available wherever Python is installed.
jsonwatch Track changes in JSON data from the command line. Works like watch -d.
lobar Explore JSON interactively or process it in batch with a wrapper for lodash.chain(). An alternative to jq with a JavaScript syntax.
rq Create and manipulate JSON with a DSL inspired by Rust, C and JavaScript. Similar to jq. Supports JSON, YAML and TOML as well as binary formats like Apache Avro and MessagePack.
validjson Validate or pretty-print JSON.

YAML, TOML

With a format converter like Remarshal (below) you can use JSON tools to process YAML and TOML, but make sure you do not lose data in the conversion.

Name and link Description
Remarshal Convert between YAML, TOML, and JSON. Validate or pretty-print each of the three formats.
rq See the JSON section.
shyaml Query YAML. Can output null-terminated strings for use in shell scripts.
validtoml Validate TOML.
validyaml Validate or pretty-print YAML.
yq (kislyuk) jq wrapper for YAML.
yq (mikefarah) Query, modify, and merge YAML. Convert to and from JSON.

INI

Name and link Platform License Description
confget Linux, FreeBSD Two-clause BSD Retrieve properties and sections as shell script commands to set the corresponding variables. Retrieve properties' values as plain text. Check for existence of properties. List sections. Find values that match a pattern. Read-only.
crudini Any with Python 2.x GNU GPLv2 Retrieve properties and sections as INI fragments or shell script commands to set the corresponding variables. Retrieve properties' values as plain text. Set properties. Remove properties and sections. Create empty sections. Merge INI files. Changes files in place.
IniFile (DOS version) Windows (x86, x86-64), MS-DOS Closed-source freeware Retrieve properties and sections as batch file commands to set the corresponding variables. Set properties. Remove properties and sections. Changes files in place.
initool Windows, Linux, FreeBSD MIT Retrieve properties and sections as INI fragments. Retrieve properties' values as plain text. Set properties. Check for existence of properties and sections. Remove properties and sections. Outputs the updated INI file.

Configuration files

Name and link Description
Augeas Query and modify a number of file formats. Not all of the formats are equally well supported by Augeas and for some only a limited subset of all valid files can be parsed.
Elektra Query and modify configuration files. Shares Augeas' limitations when it comes to application-specific configuration files (it uses the same lenses), but has better support for generic formats such as JSON and INI.

Bonus round: CLIs for single-file databases

Name and link Description File format
Firebird Firebird is a FOSS database that can be used from a single file, like SQLite. "isql is a program that allows the user to issue arbitrary SQL commands". Binary
GNU Recutils "[A] set of tools and libraries to access human-editable, plain text databases called recfiles." Text-based, roughly "key: value"
SDB "[A] simple string key/value database based on djb's cdb disk storage and supports JSON and arrays introspection." Binary
sqlite3(1) "[A] simple command-line utility [...] that allows the user to manually enter and execute SQL statements against an SQLite database." Binary

License

The contents of this document is licensed under the Creative Commons Attribution 4.0 International License. By contributing you agree to release your contribution under this license.

Disclosure

csv2html, Sqawk, jsonwatch, Remarshal and initool are developed by the curator of this document.

About

A list of command line tools for manipulating structured text data

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published