GithubHelp home page GithubHelp logo

ahmedgaber77 / wc Goto Github PK

View Code? Open in Web Editor NEW
0.0 1.0 0.0 1.34 MB

A minimalist implementation of the Unix wc command line tool. Learn about modular design, option parsing, and standard input handling. Supports counting words, lines, characters, and bytes in files or standard input.

Makefile 1.12% Go 98.88%

wc's Introduction

Build Your Own wc Tool

This repository contains my implementation of the Unix command line tool wc in Go. Through this project, I learned about writing simple, modular programs with clean interfaces and how to design programs to be easily connected to other tools.

What I Learned

  • Unix Philosophy: Understanding the importance of writing simple parts connected by clean interfaces.
  • Functional Requirements: Implementing word, line, character, and byte count functionalities.
  • Handling Command Line Options: Supporting various command line options (-c, -l, -w, -m) and the default behavior.
  • Reading from Standard Input: Enabling the tool to read from standard input if no filename is specified.

Challenges Faced

  • Modular Design: Structuring the code to ensure each function handles one task efficiently.
  • Option Parsing: Parsing command line options and determining the appropriate action for each.
  • Locale Considerations: Handling multibyte characters for accurate character count (-m option).
  • Error Handling: Ensuring robust error handling to handle invalid inputs and edge cases.

Conclusion

Building this wc tool was a rewarding challenge that deepened my understanding of software engineering principles and command line tool development. It provided valuable insights into modular design, option parsing, and handling different input sources.

Usage

Run the program using the following syntax:

go run main.go [flags] filename

Available Flags:

  • -l: Prints the number of newline characters (lines).
  • -c: Prints the total byte count of the input.
  • -m: Prints the total character count of the input.

If no flags are specified, the program will display all counts.

Examples:

  1. Count lines in a file named file.txt:
go run main.go -l file.txt
  1. Count characters in a string:
echo "This is a test string." | go run main.go -m

Building

To build an executable named wc for your current directory, use the following command:

go build -o wc main.go

This allows you to run the program without the go run prefix:

./wc [flags] filename

wc's People

Contributors

ahmedgaber77 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.