Fast Grep

Description

Discuss (8 comments)
The goal of this puzzle is to find the first line that contains a given word and to print its number on the standard output.

If no line is found that contains the given word, the value 0 should be printed. The match should be case-sensitive (the word must match the same case as the input-argument's case).

Input Specifications

Your program must take 2 arguments:
  1. the word to look for
  2. the input file in which to search for the word
The input file contains only a word per line.
For example, let this be myfile.txt:
Hello
World

Output Specifications

The output result should printed on the standard output. The result to be printed is the number of the line where the keyword was first found, or 0 if the keyword cannot be found.

Calling your program with the following arguments:
your_program_name Hello myfile.txt
Must produce the following output:
1
© CoderCharts - All Rights Reserved
Type Puzzle Pass 848 Fail 623
Scoring Language Level Easy Points 100
Tags file reading

Source code editor

Unit Tests

Name CPU Unit Memory Unit

Simple test

Testing the rest of the example
1s
250 MB

Big file, test #1

A word near the beginning
1s
250 MB

Big file, test #2

A word near the end
1s
250 MB

Big file, test #3

A missing word due to case
1s
250 MB

Big file, test #4

A missing word
1s
250 MB

Confirm that you want to switch languages
Your current edits will be lost.

Confirm that you wish to load a previous submission
Your current edits will be lost.