https://github.com/shoenig/fields
fields extracts columns of text (replace awk/cut)
https://github.com/shoenig/fields
awk cli cut fields go golang hacktoberfest
Last synced: 5 months ago
JSON representation
fields extracts columns of text (replace awk/cut)
- Host: GitHub
- URL: https://github.com/shoenig/fields
- Owner: shoenig
- License: mit
- Created: 2017-07-11T03:28:04.000Z (over 8 years ago)
- Default Branch: main
- Last Pushed: 2023-06-01T10:58:37.000Z (over 2 years ago)
- Last Synced: 2025-07-17T05:38:23.487Z (7 months ago)
- Topics: awk, cli, cut, fields, go, golang, hacktoberfest
- Language: Go
- Homepage: https://sethops1.net/post/extract-columns-with-fields/
- Size: 51.8 KB
- Stars: 10
- Watchers: 2
- Forks: 0
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
fields
======
Use the `fields` CLI command as a modern replacement for `awk` + `cut`.
With fields you specify which columns of text you want, in a flexible format.

[](https://github.com/shoenig/fields/actions/workflows/ci.yml)
# Getting Started
#### Build from source
The `fields` command can be installed via Go by running
```bash
$ go install github.com/shoenig/fields/cmd/fields@latest
```
# Example Usages
#### select a single column (from left)
```bash
$ fields 3 <<< "a b c d e f g"
c
```
#### select a single column (from right)
```bash
$ fields -- -3 <<< "a b c d e f g"
e
```
#### select multiple columns
```bash
$ fields 1,-1,2,-2 <<< "a b c d e f g"
a g b f
```
#### select columns to the right of N (from left)
```bash
$ fields 4: <<< "a b c d e f g"
d e f g
```
#### select columns to the right of N (from right)
```bash
$ fields -- -2: <<< "a b c d e f g"
f g
```
#### select columns to the left of N (from left)
```bash
$ fields :2 <<< "a b c d e f g"
a b
```
#### select columns to the left of N (from right)
```bash
$ fields :-2 <<< "a b c d e f g"
a b c d e f
```
#### select range of columns
```bash
$ fields 2:5 <<< "a b c d e f g"
b c d e
```
#### any combination of the above, all together
```bash
$ fields 1,2,-2,3:5,2:,:-3 <<< "a b c d e f g"
a b f c d e b c d e f g a b c d e
```
# Contributing
The `github.com/shoenig/fields` module is always improving with new features
and error corrections. For contributing bug fixes and new features please file an issue.
# License
The `github.com/shoenig/fields` module is open source under the [MIT](LICENSE) license.