Giter Site home page Giter Site logo

ccwc's Introduction

Build My Own wc Tool

NB: First of all, this script uses Python 3.8.2

This challenge is to build my own version of the Unix command line tool wc.

The Challenge - Build wc

The functional requirements for wc are concisely described by its man page - give it a go in a local terminal:

man wc

The TL/DR version is: wc - word, line, character, and byte count.

There are 2 text files, test.txt, and usage.txt, used to check the behavior of the original wc and my version, ccwc.


Write a simple version of wc, let’s call it ccwc (cc for Coding Challenges).

  1. flag -c = number of bytes in a file

The output should match this:

wc -c test.txt
  342190 test.txt

wc -c test.txt usage.txt
  342190 test.txt
    1152 usage.txt
  343342 total
python3 ccwc.py -c test.txt
  342190 test.txt

python3 ccwc.py -c test.txt usage.txt
  342190 test.txt
    1152 usage.txt
  343342 total
  1. flag -l = number of lines in a file

The output should match this:

wc -l test.txt
  7145 test.txt

wc -l test.txt usage.txt
  7145 test.txt
    27 usage.txt
  7172 total
python3 ccwc.py -l test.txt
  7145 test.txt

python3 ccwc.py -l test.txt usage.txt
  7145 test.txt
    27 usage.txt
  7172 total
  1. flag -m = number of characters in a file

The output should match this:

wc -m test.txt
  339292 test.txt

wc -m test.txt usage.txt
  339292 test.txt
    1152 usage.txt
  340444 total
python3 ccwc.py -m test.txt
  339292 test.txt

python3 ccwc.py -m test.txt usage.txt
  339292 test.txt
    1152 usage.txt
  340444 total
  1. flag -w = number of words in a file

The output should match this:

wc -w test.txt
  58164 test.txt

wc -w test.txt usage.txt
  58164 test.txt
    168 usage.txt
  58332 total
python3 ccwc.py -w test.txt
  58164 test.txt

python3 ccwc.py -w test.txt usage.txt
  58164 test.txt
    168 usage.txt
  58332 total
  1. No flag = -l, -w, and -c together

The output should match this:

wc test.txt
  7145 58164 342190 test.txt

wc test.txt usage.txt
  7145 58164 342190 test.txt
    27   168   1152 usage.txt
  7172 58332 343342 total
python3 ccwc.py test.txt
  7145 58164 342190 test.txt

python3 ccwc.py test.txt usage.txt
  7145 58164 342190 test.txt
    27   168   1152 usage.txt
  7172 58332 343342 total
  1. No argument = read from standard input
cat test.txt | wc -l
  7145
cat test.txt | python3 ccwc.py -l
  7145

ccwc's People

Contributors

tonybnya 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.