Last active
February 21, 2016 03:29
-
-
Save mikezila/564aa57c92322bf42aeb to your computer and use it in GitHub Desktop.
A simple grep clone that also shows line numbers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
namespace grope | |
{ | |
class MainClass | |
{ | |
public static void Main (string[] args) | |
{ | |
if (args.Length == 0) { | |
Console.WriteLine ("Usage: grope searchTerm\nReceives input from stdin."); | |
return; | |
} | |
int lineNumber = 1; | |
if (args.Length == 1) { | |
string line; | |
while ((line = Console.ReadLine ()) != null) { | |
if (line.Contains (args [0])) | |
Console.WriteLine (lineNumber + " " + line.Trim ()); | |
lineNumber++; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment