Thread: Search text files for matching strings

  1. #1
    Registered User
    Join Date
    Aug 2009

    Search text files for matching strings

    I need some help.

    Here's what I would like to do. I'd like to import a test file with a list of search terms. Then I'd like to have the program search another text file to see if the terms exist.

    The input file will be a list of server names and/or IP addresses, so they will be a single item per line.

    The text file to be searched is a router configuration, so each line will vary in length.

    Any thoughts on the best way to do this?


  2. #2
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    grep, and/or Perl.

    If you want to code it yourself, in C++, you could create a std::set of the search terms, and then for each term in the "other file", just check to see if it exists in the std::set. That would probably be more efficient but less esoteric and less fun than using grep.

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell

    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ:

    My website:
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. String search in two text files
    By ab-c in forum C Programming
    Replies: 2
    Last Post: 07-14-2008, 04:01 AM
  2. Help with loading files into rich text box
    By blueparukia in forum C# Programming
    Replies: 3
    Last Post: 10-19-2007, 12:59 AM
  3. displaying text files, wierd thing :(
    By Gades in forum C Programming
    Replies: 2
    Last Post: 11-20-2001, 05:18 PM
  4. string array text search
    By ery in forum C++ Programming
    Replies: 2
    Last Post: 11-18-2001, 03:00 PM
  5. Sorting strings to speed up search?
    By Mox in forum C++ Programming
    Replies: 5
    Last Post: 09-10-2001, 12:17 PM