Coding Challenge #10 - uniq
Photo by Mulyadi on Unsplash

Coding Challenge #10 - uniq

This weeks challenge is to build your own version of the Unix command line tool uniq.

I’m a big fan of the Unix Philosophy and the command line tools it has spawned. By chaining them together you can create complex and powerful software from simple building blocks. That’s a great model to follow for the functions and modules in the software you write and the components you use in the systems you build as a software developer.

The Challenge - Building uniq

Let’s check out the man page on uniq to find out what it does:

The uniq utility reads the specified input_file comparing adjacent lines, and
writes a copy of each unique input line to the output_file.  If input_file is a
single dash (‘-’) or absent, the standard input is read.  If output_file is 
absent, standard output is used for output.  The second and succeeding copies 
of identical adjacent input lines are not written.  Repeated lines in the input
will not be detected if they are not adjacent, so it may be necessary to sort 
the files first.        

Step Zero

Like most programming languages we’re zero indexed!

For this step, I’ll leave you to setup your IDE / editor of choice and programming language of choice. After that here’s what I’d like you to do to be ready to test your solution.

Download the test data from my?dropbox here?and unzip it.

Step 1

In this step your goal is to read an input file and and handle the default behaviour, which is to remove duplicate adjacent lines.

For example the input:

line1
line2
line2
line3
line4        

would become:

% uniq test.txt
line1
line2
line3
line4        

You can test your program using the above or on the countries list:

% uniq countries.txt | wc -l
246        

Continued....

You can find Step 2 and beyond on the?Coding Challenges?website as?Write You Own uniq.

Or if you'd rather get the whole challenge delivered to you inbox every week, you can subscribe on the?Coding Challenges Substack.


Mohit Jain

Software Tech Lead @Zemetric | ex Co-Founder @Evy Energy (Acquired)

1 年

This was a short and sweet tool to build. Thanks, John Crickett, for the challenges. Here's my solution in TypeScript: https://github.com/jainmohit2001/coding-challenges/tree/master/src/10

要查看或添加评论,请登录

John Crickett的更多文章

  • Coding Challenge #86 - Strace

    Coding Challenge #86 - Strace

    This challenge is to build your own version of Linux tool strace. It’s a useful tool to debug programs that you don’t…

    2 条评论
  • From The Challenges - Memcached Server

    From The Challenges - Memcached Server

    ?? ?? Happy Birthday Coding Challenges - Two Years Old! ?? ?? Coding Challenges is turning two this week! To celebrate…

    13 条评论
  • Coding Challenge #85 - Time Zone Converter

    Coding Challenge #85 - Time Zone Converter

    Coding Challenge #85 - Time Zone Converter This challenge is to build your own Time Zone Converter. That is a tool to…

    12 条评论
  • From The Challenges - IRC Client

    From The Challenges - IRC Client

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    5 条评论
  • Coding Challenge #84 - Mandelbrot Set Explorer

    Coding Challenge #84 - Mandelbrot Set Explorer

    This challenge is to build your own Mandelbrot set explorer. The Mandelbrot set is a set of fractals that exhibit great…

    4 条评论
  • From The Challenges - Cat

    From The Challenges - Cat

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    7 条评论
  • Coding Challenge #83 - Markdown Presentation Tool

    Coding Challenge #83 - Markdown Presentation Tool

    Coding Challenge #83 - Markdown Presentation Tool This challenge is to build your own version of Go’s Present or…

    3 条评论
  • From The Challenges - Shell

    From The Challenges - Shell

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    3 条评论
  • Coding Challenge #82 - Markdown To PDF Editor

    Coding Challenge #82 - Markdown To PDF Editor

    Coding Challenge #82 - Markdown To PDF Editor This challenge is to build your own tool to convert markdown to PDF. It…

    14 条评论
  • From The Challenges - Diff

    From The Challenges - Diff

    Welcome To Coding Challenges - From The Challenges! In this Coding Challenges “from the challenges” newsletter I’m…

    7 条评论

社区洞察

其他会员也浏览了