/xtee

A versatile command-line interface (CLI) utility for handling data streams in Unix-like environments. It serves as a crucial link between standard input and dual outputs, taking a single stream of input and splitting it into two outputs, one to the standard output and the other to a file simultaneously.

Primary LanguageGoMIT LicenseMIT

xtee

made with go go report card release open issues closed issues license maintenance contribution

xtee is a versatile command-line utility handy in taking a single stream of input, from standard input, and splitting it into two outputs, standard output and file.

Resources

Features

  • Splits incoming standard input into standard output and file.
  • Supports soaking up input before writing to output file.
  • Supports appending and overwriting outputs.
  • Supports deduplication.
  • Cross-Platform (Windows, Linux & macOS).

Installation

Install release binaries (without Go installed)

Visit the releases page and find the appropriate archive for your operating system and architecture. Download the archive from your browser or copy its URL and retrieve it with wget or curl:

  • ...with wget:

     wget https://github.com/hueristiq/xtee/releases/download/v<version>/xtee-<version>-linux-amd64.tar.gz
  • ...or, with curl:

     curl -OL https://github.com/hueristiq/xtee/releases/download/v<version>/xtee-<version>-linux-amd64.tar.gz

...then, extract the binary:

tar xf xtee-<version>-linux-amd64.tar.gz

Tip

The above steps, download and extract, can be combined into a single step with this onliner

curl -sL https://github.com/hueristiq/xtee/releases/download/v<version>/xtee-<version>-linux-amd64.tar.gz | tar -xzv

Note

On Windows systems, you should be able to double-click the zip archive to extract the xtee executable.

...move the xtee binary to somewhere in your PATH. For example, on GNU/Linux and OS X systems:

sudo mv xtee /usr/local/bin/

Note

Windows users can follow How to: Add Tool Locations to the PATH Environment Variable in order to add xtee to their PATH.

Install source (with Go installed)

Before you install from source, you need to make sure that Go is installed on your system. You can install Go by following the official instructions for your operating system. For this, we will assume that Go is already installed.

go install ...

go install -v github.com/hueristiq/xtee/cmd/xtee@latest

go build ... the development version

  • Clone the repository

     git clone https://github.com/hueristiq/xtee.git 
  • Build the utility

     cd xtee/cmd/xtee && \
     go build .
  • Move the xtee binary to somewhere in your PATH. For example, on GNU/Linux and OS X systems:

     sudo mv xtee /usr/local/bin/

    Windows users can follow How to: Add Tool Locations to the PATH Environment Variable in order to add xtee to their PATH.

Caution

While the development version is a good way to take a peek at xtee's latest features before they get released, be aware that it may have bugs. Officially released versions will generally be more stable.

Usage

To display help message for xtee use the -h flag:

xtee -h

help message:


      _
__  _| |_ ___  ___
\ \/ / __/ _ \/ _ \
 >  <| ||  __/  __/
/_/\_\\__\___|\___|
             v0.4.0

USAGE:
 xtee [OPTION]... <FILE>

INPUT OPTIONS:
     --soak bool        soak up all input before writing to file

OUTPUT OPTIONS:
 -u, --unique bool      output unique lines
 -a, --append bool      append lines to output
 -q, --quiet bool       suppress output to stdout
 -p, --preview bool     preview new lines, without writing to file

pflag: help requested
  • Appending Unique Lines to File

     ➜  cat stuff.txt
     one
     two
     three
    
     ➜  cat new-stuff.txt
     zero
     one
     two
     three
     four
     five
    
     ➜  cat new-stuff.txt | xtee stuff.txt --append --unique
     zero
     four
     five
    
     ➜  cat stuff.txt
     one
     two
     three
     zero
     four
     five
    
    

    Note that the new lines added to stuff.txt are also sent to stdout, this allows for them to be redirected to another file:

     ➜  cat new-stuff.txt | xtee stuff.txt --append --unique > added-lines.txt
     ➜  cat added-lines.txt
     zero
     four
     five
    
  • Deduplicating Files

     ➜  cat stuff.txt
     zero
     one
     two
     three
     zero
     four
     five
     five
    
     ➜  cat stuff.txt | xtee stuff.txt --soak --unique
     zero
     one
     two
     three
     four
     five
    
     ➜  cat stuff.txt
     zero
     one
     two
     three
     four
     five
    
    

    Note the use of --soak, it makes the utility soak up all its input before writing to a file. This is useful for reading from and writing to the same file in a single pipeline.

Contributing

We welcome contributions! Feel free to submit Pull Requests or report Issues. For more details, check out the contribution guidelines.

Licensing

This utility is licensed under the MIT license. You are free to use, modify, and distribute it, as long as you follow the terms of the license. You can find the full license text in the repository - Full MIT license text.

Credits

Contributors

A huge thanks to all the contributors who have helped make xtee what it is today!

contributors

Similar Projects

If you're interested in more utilities like this, check out:

tomnomnom/anewrwese/anew ◇ tee (coreutils) ◇ sponge (moreutils)