Add options for case-insensitivity, blank lines, output file, counts, and backup to anew #30
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi Maintainers,
This PR enhances the
anewuniqueness tool by adding several commonly requested features to improve its flexibility and usability in various scenarios. The goal was to add practical options without significantly increasing the tool's complexity.Motivation:
The base
anewtool is useful for ensuring unique lines, but real-world use cases often require more nuanced handling:Changes Introduced:
This PR adds the following command-line options to
anew:-i(Ignore Case): Performs case-insensitive comparisons when checking for existing lines and duplicates from stdin.-B(Ignore Blank Lines): Skips processing (and potentially adding) blank lines received from standard input.-o <outfile>(Output File): Specifies a different file to append the new unique lines to. If omitted, behavior remains the same (appends to the[input_filename]if provided). This allows merging unique lines into a new destination.-c(Counts): Prints statistics (lines read, duplicates found, blanks skipped, lines output/written) to stderr upon completion.cat new_stuff.txt | anew -c existing.txt--backup[=<SUFFIX>](Backup): Creates a backup copy of the[input_filename]before modification. This only takes effect if output is being written back to the same file specified as[input_filename](i.e.,-ois not used or-opoints to the same file).--backupis used without a value, the suffix.bakis used.--backup=<SUFFIX>is used, the specifiedSUFFIXis appended to the filename (e.g.,--backup=.orig).Internal Improvements:
Configstruct.Statsstruct for collecting counts.normalizeLinehelper function to handle trimming and case-folding consistently.ErrNotExist, checking scanner errors).bufio.Writerfor potentially more efficient file appends.Testing:
Manual testing was performed with various combinations of flags, input files (existing, non-existing), stdin content (with duplicates, blanks, case variations), and output scenarios (in-place,
-o, dry-run).Request for Review:
Please review the changes for correctness, adherence to project style, and potential edge cases. Particular attention to the logic for
-o,--backup, and the interaction between-i,-t, and-Bwould be appreciated.Thanks for considering this contribution!