Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iang/go-uniq
A slimmed down version of the *nix uniq tool written in go
https://github.com/iang/go-uniq
Last synced: 2 days ago
JSON representation
A slimmed down version of the *nix uniq tool written in go
- Host: GitHub
- URL: https://github.com/iang/go-uniq
- Owner: IanG
- Created: 2024-07-23T11:06:18.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-07-23T11:42:52.000Z (6 months ago)
- Last Synced: 2024-11-30T11:08:47.478Z (2 months ago)
- Language: Go
- Homepage:
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-uniq
This is a solution to [John Crickett](https://www.linkedin.com/in/johncrickett/)'s Coding Challenges [Build Your Own uniq Tool](https://codingchallenges.fyi/challenges/challenge-uniq) in go.
This is a very basic implementation of the `uniq` command used in the shell on most *nix-like operating systems.
It makes use of the `flags` go package for handling command line parameters## Building Locally
build the code with:
`go build`
this will create the `uniq` binary in your local directory.
## Running
### Getting Help
View command line options with `./uniq -h`. This will output:```
Usage: ./uniq [OPTIONS] [inputfile] [outputfile]
-c Count occurrences
-count
Count occurrences
-d Print only repeated lines
-repeated
Print only repeated lines
-u Print only unique lines
-unique
Print only unique lines
[inputfile] can either be the path to an input file or '-' for stdin
[outputfile] can either be the path to an output file or '-' for stdout
```### Finding the unique lines in a file
You can find the unique lines in a file with:
`./uniq ./testdata/test.txt`
This will output:
```
line1
line2
line3
line4
```
You can also pipe input from stdin instead of specifying the filename with:`cat ./testdata/test.txt | ./uniq -`
### Finding the repeated lines in a file
You can find the repeated lines in a file with:
`./uniq -d ./testdata/test.txt`
This will output:
```
line2
```You can find out how many times repeated lines occur in the file with:
`./uniq -d -c ./testdata/test.txt`
This will output:
```
2 line2
```