Skip to content

Conversation

@watzon
Copy link
Contributor

@watzon watzon commented Jul 5, 2025

This PR implements the comm utility for comparing two sorted files line by line.

Implementation Details

The utility follows the GNU coreutils specification and includes:

Core Features:

  • Compare two sorted files and display differences in three columns
  • Column 1: Lines unique to file 1
  • Column 2: Lines unique to file 2
  • Column 3: Lines present in both files

Command Line Options:

  • -1: Suppress column 1 (lines unique to FILE1)
  • -2: Suppress column 2 (lines unique to FILE2)
  • -3: Suppress column 3 (lines that appear in both files)
  • --check-order: Check that input files are correctly sorted
  • --nocheck-order: Do not check sort order
  • --output-delimiter=STRING: Use STRING to separate columns (default: TAB)
  • --total: Display a summary with counts for each column
  • -z, --zero-terminated: Use NUL as line delimiter instead of newline

Additional Features:

  • Support for stdin using - as filename
  • Proper error handling with appropriate exit codes
  • Full compatibility with BSD comm (macOS) for standard options
  • GNU extensions for enhanced functionality

Testing

Comprehensive test suite included covering:

  • Basic file comparison
  • All column suppression combinations
  • Empty file handling
  • Stdin support
  • Error cases (missing files, wrong number of arguments)
  • Custom delimiter functionality

All tests pass and the implementation matches the behavior of GNU coreutils comm.

Progress Update

This brings the project to 75/109 utilities completed (69%). Nice!

@JalonSolov
Copy link
Contributor

Need to format comm_test.v.

Also appears we have a problem with the sort command. :-\

@watzon
Copy link
Contributor Author

watzon commented Jul 6, 2025

Yeah... the test suite also seems to be very broken on macOS in general

@JalonSolov JalonSolov merged commit dc1bb11 into vlang:main Jul 14, 2025
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants