Skip to content

MrSheerluck/go-cat

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-cat

A Go implementation of the Unix cat command with support for common flags.

Features

  • Read and display file contents
  • Support for multiple files
  • Stream-based reading (memory efficient for large files)
  • Command-line flags for enhanced output

Supported Flags

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

Building

go build -o go-cat

Usage

Basic usage

./go-cat file.txt

Display multiple files

./go-cat file1.txt file2.txt file3.txt

Number all lines

./go-cat -n file.txt

Number non-empty lines

./go-cat -b file.txt

Squeeze blank lines

./go-cat -s file.txt

Show end of lines

./go-cat -E file.txt

Combine flags

./go-cat -n -E file.txt
./go-cat -b -s file.txt

Implementation Notes

  • Uses bufio.Scanner for line-based streaming
  • Flag priority: -b takes precedence over -n when both are set
  • Handles files without trailing newlines correctly
  • Clean separation of concerns with LineConfig struct and printLine() helper function

Development Journey

Built incrementally from:

  1. Single file reading
  2. Multiple file support
  3. Stream-based reading optimization
  4. Flag parsing and implementation
  5. Code refactoring for maintainability

About

A Go implementation of the Unix cat command with support for common flags.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages