Skip to content
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

Output regex match rather than result #107

Open
brandonhaberfeld opened this issue Jul 25, 2019 · 0 comments
Open

Output regex match rather than result #107

brandonhaberfeld opened this issue Jul 25, 2019 · 0 comments

Comments

@brandonhaberfeld
Copy link

brandonhaberfeld commented Jul 25, 2019

Neither grep nor sift can do what I describe below, but since sift is by far the better tool (use it absolutely everywhere), it would be better implemented here than grep:

We would like an option in sift that causes the rules used when a regex match is successful to be printed from the sift -f syntax, rather than the actual result (or both if someone needs that).

ie: file1 : contains a list of regex patterns to match against
file2 : contains the text to search or stdin if piped.

sift -f file_of-regex-patterns files-to-search-in
Wherever a file contains one of the regex patterns, return the pattern rather than the line in the files that matched (optionally)

Many people seem to want to do this (google search) and yet the only option is to iterate through all the lines is the searched text match one at a time to find which pattern worked.... awk is typically suggested but its regex engine is inferior.

Here an exmaple: The regexs to match some commands are:
File: patterns
.cmd1 (parm1|parm2|parm3)
^cmd2.
.sh (arg1|arg2)

Some text files contains various commands with options arguments and parameters:
file1: cmd1 parm2
file2: mycmd1 parm3
file3: cmd2-test-.sh arg2
file4: cmd2-test2.sh arg1

sift -f patterns file*
The output would be the lines of the pattern file that patched:
.cmd1 (parm1|parm2|parm3)
.cmd1 (parm1|parm2|parm3)
^cmd2.
.sh (arg1|arg2)
^cmd2.
.sh (arg1|arg2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant