Home | Blog | Software | Reviews and Features | Forum | Help | Donate | About us
topbanner_forum
  *

avatar image

Welcome, Guest. Please login or register.
Did you miss your activation email?

Login with username, password and session length
  • December 08, 2016, 01:58:46 AM
  • Proudly celebrating 10 years online.
  • Donate now to become a lifetime supporting member of the site and get a non-expiring license key for all of our programs.
  • donate

Author Topic: multi string search in file  (Read 4781 times)

Blue4ce

  • Supporting Member
  • Joined in 2008
  • **
  • default avatar
  • Posts: 1
    • View Profile
    • Donate to Member
multi string search in file
« on: November 05, 2008, 07:00:56 PM »
hi,

I have a list(1)

aaaa
bbbb
cccc
dddd
eeee
ffffff
eeee
bbbb

and I would like to search for list(2)

aaaa
eeee
xxxx

in list(1)

Is there any gui tool / text editor which can,
1) accept infile for "find what" or multiple lines of input in "find what"
2) highlight found items in the text, corresponding to any line of the "find what" patterns

I want to see something like this.

aaaa
bbbb
cccc
dddd
eeee
ffffff
eeee
bbbb

Hope I am clear enough .  :)

I dont want to format my "find what" strings into regular expressions, every time I do such a search.

Thanks.

rjbull

  • Charter Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 2,927
    • View Profile
    • Donate to Member
Re: multi string search in file
« Reply #1 on: November 06, 2008, 04:42:14 AM »
Freeware - WanyWord.

If you're prepared to spend money - HFFR Text Workbench.  It's meant for search and replace, but you can use it in search-only mode.  I haven't looked at the cheaper editions.

Not sure either of them will present the results in exactly the format you suggest, but both will search for multiple strings.  You can still find the last free version of HFFR around the Net, but it doesn't match your criterion because it will only search for a single string.

housetier

  • Charter Honorary Member
  • Joined in 2005
  • ***
  • default avatar
  • Posts: 1,321
    • View Profile
    • Donate to Member
Re: multi string search in file
« Reply #2 on: November 06, 2008, 07:15:51 AM »
if I understood the man page correctly this will work partially:

grep --color=auto -f needle haystack
where needle is your second list (the stuff to look FOR) and haystack is your first list (the stuff to look IN)

like so
housetier@reliant:/tmp$ cat haystack
aaaa
bbbb
cccc
dddd
eeee
ffffff
eeee
bbbb
housetier@reliant:/tmp$ cat needle
aaaa
eeee
xxxx
housetier@reliant:/tmp$ grep -f needle haystack
aaaa
eeee
eeee
housetier@reliant:/tmp$



After asking for help in the #c-base channel on freenode, we came up with this:
grep --color=auto -C $(wc -l < haystack) -f needle haystack

which looks
like so
housetier@reliant:/tmp$ grep -C $(wc -l < haystack) -f needle haystack
aaaa
bbbb
cccc
dddd
eeee
ffffff
eeee
bbbb


This solution is completely free ;)

fiddyschmitt

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 17
    • View Profile
    • www.jimmythefork.com
    • Donate to Member
Re: multi string search in file
« Reply #3 on: January 25, 2009, 07:42:02 AM »
you could try hound (freeware) which is a program I wrote. It's on my website:
www.jimmythefork.com

cheers,
Fidel

mouser

  • First Author
  • Administrator
  • Joined in 2005
  • *****
  • Posts: 36,412
    • View Profile
    • Mouser's Software Zone on DonationCoder.com
    • Read more about this member.
    • Donate to Member
Re: multi string search in file
« Reply #4 on: January 25, 2009, 08:33:18 AM »
Hey fidel! Welcome to the site! Always really fun to have another coder drop by and hang out.  Hope you will make yourself at home.

fiddyschmitt

  • Honorary Member
  • Joined in 2009
  • **
  • Posts: 17
    • View Profile
    • www.jimmythefork.com
    • Donate to Member
Re: multi string search in file
« Reply #5 on: January 25, 2009, 08:43:06 AM »
thanks mouser :) there's lot of great stuff to read here, I've been on the site for hours!