New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GrepOption.lineNumber not working #58

Closed
segaura opened this Issue Aug 3, 2018 · 6 comments

Comments

Projects
None yet
2 participants
@segaura

segaura commented Aug 3, 2018

My code has something like

Unix4j.fromFile(path).grep(GrepOption.lineNumber, EVIL_REGEX).toStdOut();

all the lines I want to match are correctly matched, but the output does not have the line number prefix at the beginning of each line

(Java 8, Windows 64bit)

@terzerm

This comment has been minimized.

Member

terzerm commented Aug 4, 2018

Thanks for using Unix4j.

Can you be a bit more specific?

  • Which version of unix4j are you using
  • What is your input EVIL_REXEX ?

Best practice is to provide a unit test that reproduces the problem.

Thank you!

@terzerm terzerm added the bug label Aug 4, 2018

@terzerm terzerm self-assigned this Aug 4, 2018

@terzerm

This comment has been minimized.

Member

terzerm commented Aug 4, 2018

Something is certainly not quite right with counting and line numbers --- working on a fix.

Would still be helpful to get some more details of the test failure, or better a unit test that demonstrates the failure.

@segaura

This comment has been minimized.

segaura commented Aug 4, 2018

Sorry, I thougth I provided a test case because that was actually the only line of code :-)

package com.mycompany.codeanalyzer;

import org.unix4j.Unix4j;
import org.unix4j.unix.grep.GrepOption;

public class LineOptionTest {

private static final String INPUT_PATH = "D:\\theFolder\\theFileName.theFileExtension";
    private static final String EVIL_REGEX = "anyStringOrRegexpITried";	

    public static void main(String[] args) {
        Unix4j.fromFile(INPUT_PATH).grep(GrepOption.lineNumber, EVIL_REGEX).toStdOut();
   }

}

the file content at INPUT_PATH is

anyStringOrRegexpITried

and the program output is

anyStringOrRegexpITried

The real program uses the Find class that works like a charm, walking through a complete folders structure, so I tested this grep() with a great number of files and I never saw a line number in the output, so far.

@terzerm

This comment has been minimized.

Member

terzerm commented Aug 5, 2018

Cool thank you. Will work on a fix in the coming days.

@terzerm terzerm added the Version-0.6 label Aug 8, 2018

@terzerm

This comment has been minimized.

Member

terzerm commented Aug 8, 2018

Test covering this case:
GrepTest.testLineNumberWithRegex()

terzerm added a commit that referenced this issue Aug 8, 2018

@segaura

This comment has been minimized.

segaura commented Aug 10, 2018

My BIG fault.
I started from an example and included unix4j-command version 0.3 (I forgot to include pom.xml in the issue).
Moving to version 0.5 solved the issue, now line numbers are shown.

I am very sorry, the issue can be closed.

@segaura segaura closed this Aug 10, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment