A Go implementation of the Unix cat command with support for common flags.
- Read and display file contents
- Support for multiple files
- Stream-based reading (memory efficient for large files)
- Command-line flags for enhanced output
| Flag | Description |
|---|---|
-n |
Number all lines |
-b |
Number non-empty lines only |
-s |
Squeeze consecutive blank lines into one |
-E |
Show end of line with $ character |
go build -o go-cat./go-cat file.txt./go-cat file1.txt file2.txt file3.txt./go-cat -n file.txt./go-cat -b file.txt./go-cat -s file.txt./go-cat -E file.txt./go-cat -n -E file.txt
./go-cat -b -s file.txt- Uses
bufio.Scannerfor line-based streaming - Flag priority:
-btakes precedence over-nwhen both are set - Handles files without trailing newlines correctly
- Clean separation of concerns with
LineConfigstruct andprintLine()helper function
Built incrementally from:
- Single file reading
- Multiple file support
- Stream-based reading optimization
- Flag parsing and implementation
- Code refactoring for maintainability