FELIX-1802 - Grep command line prefix (-n) not working properly


git-svn-id: https://svn.apache.org/repos/asf/felix/trunk@829462 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java b/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
index e30e505..d527872 100644
--- a/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
+++ b/karaf/shell/commands/src/main/java/org/apache/felix/karaf/shell/commands/GrepAction.java
@@ -119,10 +119,6 @@
             while ((line = readLine(r)) != null) {
                 if (p.matcher(line).matches() ^ invertMatch) {
 
-                    if (!count && lineNumber) {
-                        System.out.print(String.format("%6d  ", lineno++));
-                    }
-
                     Matcher matcher2 = p2.matcher(line);
                     StringBuffer sb = new StringBuffer();
                     while (matcher2.find()) {
@@ -138,9 +134,12 @@
                         nb++;
                     }
                     matcher2.appendTail(sb);
-					lines.add(sb.toString());
+                    if (!count && lineNumber) {
+                        lines.add(String.format("%6d  ", lineno) + sb.toString());
+                    } else {
+                        lines.add(sb.toString());
+                    }
 					lineMatch = lines.size();
-                    lineno++;
                 } else {
                     if (lineMatch != 0 & lineMatch + after + before <= lines.size()) {
                         if (!count) {
@@ -163,6 +162,7 @@
                         lines.remove(0);
                     }
                 }
+                lineno++;
             }
             if (!count && lineMatch > 0) {
                 if (!firstPrint && before + after > 0) {