Skip to content

Instantly share code, notes, and snippets.

@mikezila
Last active February 21, 2016 03:29
Show Gist options
  • Save mikezila/564aa57c92322bf42aeb to your computer and use it in GitHub Desktop.
Save mikezila/564aa57c92322bf42aeb to your computer and use it in GitHub Desktop.
A simple grep clone that also shows line numbers.
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