/cc-wc-js

JS wc command reimagined: Conquer John Crickett's code challenge

Primary LanguageJavaScriptMIT LicenseMIT

Coding Challenges - Write Your Own wc Tool

This project implements a custom version of the Unix wc tool in JavaScript: ccwc. Like the original wc, it allows you to:

  • Count the number of bytes in a file
  • Count the number of lines in a file
  • Count the number of words in a file
  • Count the number of characters in a file

This implementation provides a fun and practical way to explore JavaScript and its capabilities.

Getting Started

  1. Installation
git clone git@github.com:victoriacheng15/cc-write-your-wc-tool.git

cd cc-write-your-wc-tool
  1. Set up
npm link
  1. Run the command
ccwc -m example.txt

Note: keep in mind, that the ccwc command only works in this directory.

Usage

This tool helps you analyze a file's size and content. You can use it to count the number of bytes, lines, words, and characters in a file.

Flag Description
-c print the byte count
-l print the lines count
-w print the words count
-m print the characters count

Basic Usage

There are two ways to use ccwc:

  1. File as input:
ccwc [option] [file]

example:

ccwc -l example.txt
  1. Standard Input

You can pip date directly to the tool using standard input:

cat example.txt | ccwc -flag

exmaple:

cat example.txt | ccwc -l

Default Behavior

If you don't specify any flag, the tool will automatically print the byte, line, word counts

example:

ccwc example.txt

# output:
7137   58159  341836 example.txt

Summary

  • Use flags to specify which count you want to see.
  • Provide a file path as input.
  • Alternatively, pipe data directly using standard input.
  • By default, the tool shows bytes, lines, and words count.

Links