https://github.com/dankinder/cl
Cl is a tool for filtering data by columns on the command line
https://github.com/dankinder/cl
bash go golang
Last synced: 2 months ago
JSON representation
Cl is a tool for filtering data by columns on the command line
- Host: GitHub
- URL: https://github.com/dankinder/cl
- Owner: dankinder
- License: mit
- Created: 2018-09-11T22:26:30.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2020-06-15T16:14:06.000Z (about 6 years ago)
- Last Synced: 2024-06-20T06:26:09.013Z (about 2 years ago)
- Topics: bash, go, golang
- Language: Go
- Size: 860 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
Cl is a tool for filtering data by columns on the command line.
# What it does
Usage: `cl [options...] `
Examples:
```bash
# Filter a simple table of data for the second column:
$ echo "1 2 3
> 4 5 6
> 7 8 9" | cl 2
2
5
8
# Grab a list of process IDs from ps, ignoring the header row (-i):
$ ps | cl 1 -i
7958
29855
# Grab the third column of output when there may be spaces, in values, and tabs are the separator (-t):
$ netstat | cl 3 -t
# Or the first 2 columns:
$ netstat | cl 1 2 -t
# Or the first 4 columns (in bash):
$ netstat | cl {1..4} -t
```
Options:
```
-i ignore the header row (first row)
-s string
a character or regex to split lines (default: whitespace)
-t use tabs as separator (alias of -s \t)
```
# Install
```bash
go get github.com/dankinder/cl
```
# Why
Existing commonly-available bash commands like `awk` and `tail` can accomplish
what `cl` does. But they become quite verbose.
To select a column with `awk`, you use:
```sh
my_command | awk '{ print $1 }'
```
But then, you want to delete the header row too (another very common thing). For that you need:
```sh
my_command | awk '{ print $1 }' | tail -n +2
```
I used to have the following bash function in my .bashrc, and I'm sure many
others have equivalents:
```bash
# Grab column N from stdin, ex. `ps aux | cl 2` => Just Process IDs
function cl() {
awk "{print \$$1}"
}
# Ignore the header row of the input
function ih() {
tail -n +2
}
```
Further, some tools worked around this specific problem by building another
tool (`pgrep`) giving us yet another command to learn.
It felt to me like we need a small, simple, generalized tool for this task.
So I build `cl`.