Skip to content

Remove duplicate lines without sorting with a fixed size buffer of last uniq strings.

Notifications You must be signed in to change notification settings

rivalsec/buffuniq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 

Repository files navigation

buffuniq

buffuniq is a simple command-line utility written in Go that filters out duplicate lines from standard input, printing only the first occurrence of each line to standard output. It uses a circular buffer to keep track of unique lines up to a specified size.

Usage

buffuniq [-n SIZE]

Options

  • -n SIZE: Specifies the size of the circular buffer used to store unique lines. If no size is provided, the default size is 100.

Example

To filter out duplicate lines from a file named input.txt and print only unique lines:

cat input.txt | buffuniq -n 100

Installation

  1. Ensure you have Go installed on your system. You can download it from https://golang.org/dl/.
  2. Clone this repository or download the source code.
  3. Navigate to the directory containing the source code.
  4. Build the binary:
    go build -o buffuniq buffuniq.go
  5. Move the buffuniq binary to a directory in your PATH, for example /usr/local/bin.

How It Works

The program reads lines from standard input and uses a circular buffer (-n SIZE) to keep track of unique lines. When a line is read, it checks if the line has been seen before using the IsNew method. If the line is new, it prints the line; otherwise, it skips it.

Circular Buffer Implementation

The program uses a slice (uniqBuff) to implement the circular buffer. The bufI index keeps track of the current position in the buffer, and size defines its capacity. When the buffer is full and a new line is added, the oldest entry is replaced by the new line.

Contributing

Feel free to fork this repository and submit pull requests for bug fixes or enhancements. Any contributions are welcome!

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

If you have any questions or feedback, please open an issue on GitHub or contact me directly.


For more detailed information and additional examples, refer to the source code comments in buffuniq.go.

About

Remove duplicate lines without sorting with a fixed size buffer of last uniq strings.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages