Find the answer to your Linux question:
Results 1 to 3 of 3
Here's a sample command... cat filetosearch.txt | fgrep -is -f matchlist.txt Obviously the normal behavior is to output the matched lines from the filetosearch.txt data file. What if my goal ...
  1. #1
    Banned
    Join Date
    Dec 2002
    Location
    Texas
    Posts
    242

    Can grep output source of a match?

    Here's a sample command...

    cat filetosearch.txt | fgrep -is -f matchlist.txt

    Obviously the normal behavior is to output the matched lines from
    the filetosearch.txt data file. What if my goal was just to find out
    which lines from the matchlist.txt list it was able to find?

    For instance...

    I don't care that "1000 Smith Street #1234" in filetosearch was found.
    But I *do* care to know that "Smith Street" from matchlist was found.

    Is there a way to do this? Obviously I could loop through the matchlist
    and do a single instance grep against the data file, but that is a bunch
    of work that seems unnecessary. Unless there's no easy way?

    Thanks!

  2. #2
    Linux Newbie
    Join Date
    Jul 2008
    Posts
    181
    grep -o (Stupid requirement to post at least ten characters).

  3. #3
    Banned
    Join Date
    Dec 2002
    Location
    Texas
    Posts
    242
    Quote Originally Posted by burschik View Post
    grep -o (Stupid requirement to post at least ten characters).
    Nice. You know, I did read the man page and saw that option but
    for some reason I wasn't thinking that it did what I was looking for.
    That's what I get for assuming, eh?

    Thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
...