https://github.com/spekulatius/first-last
Collection of bash scripts designed to improve readability of complex bash scripts with pipes.
https://github.com/spekulatius/first-last
awk bash first infosec last osint osint-tools
Last synced: about 1 month ago
JSON representation
Collection of bash scripts designed to improve readability of complex bash scripts with pipes.
- Host: GitHub
- URL: https://github.com/spekulatius/first-last
- Owner: spekulatius
- Created: 2023-06-01T10:50:04.000Z (about 3 years ago)
- Default Branch: master
- Last Pushed: 2023-06-02T18:53:23.000Z (about 3 years ago)
- Last Synced: 2025-11-27T21:40:18.961Z (7 months ago)
- Topics: awk, bash, first, infosec, last, osint, osint-tools
- Language: Shell
- Homepage: https://releasecandidate.dev
- Size: 7.81 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
Awesome Lists containing this project
README
# first-last
This collection of bash scripts aims to improve readability in complex bash scripts that involve piped data processing. It provides a set of convenient utilities to extract specific elements from piped input, simplifying data manipulation.
## Utils
### `first` / `1`, `second` / `2`, `third` / `3`, ...
These utilities retrieve the corresponding element from the piped input:
```bash
echo "one two three four five six seven eight nine ten" | first
one
```
Alternatively, you can use numeric equivalents like `1`, `2`, `3`, and so on:
```bash
echo "one two three four five six seven eight nine ten" | 1
one
```
You can use select any element from 1 to 10.
### `last`-utils
Additionally, the `last` utility retrieves the last element from the input. To access the elements in reverse order, you can use `last-1`, `last-2`, `last-3`, and so on.
### `last`
```bash
$ echo "one two three four five six" | last
six
```
### `last-1`
```bash
$ echo "one two three four five six" | last-1
five
```
### `last-2`
```bash
$ echo "one two three four five six" | last-2
four
```
### `last-3`
```bash
$ echo "one two three four five six" | last-3
three
```
### `last-4`
```bash
$ echo "one two three four five six" | last-4
two
```
### `last-5`
```bash
$ echo "one two three four five six" | last-5
one
```
## Installation
Copy the scripts somewhere and `chmod +x`
## Tests
You can run the provided test suite to validate the functionality of each utility. The test results will be displayed, indicating whether each test passed or failed, represented by a green tick (✓) for passed tests.
```bash
$ ./test
Testing 'first':
✓ Test passed
Testing 'second':
✓ Test passed
Testing 'third':
✓ Test passed
Testing 'fifth':
✓ Test passed
Testing 'sixth':
✓ Test passed
Testing 'seventh':
✓ Test passed
Testing 'eighth':
✓ Test passed
Testing 'ninth':
✓ Test passed
Testing 'tenth':
✓ Test passed
Testing 'last':
✓ Test passed
Testing 'last-1':
✓ Test passed
Testing 'last-2':
✓ Test passed
Testing 'last-3':
✓ Test passed
Testing 'last-4':
✓ Test passed
Testing 'last-5':
✓ Test passed
```