Thread: search for text string in a file

  1. #1
    Registered User
    Join Date
    May 2007

    Post search for text string in a file

    Hi there,

    I have a background as a mainframe programmer. Assembler, Cobol etc.

    Never looked a C++ before but I have a file that contains HTML source and would like to search the file for a particular text string and then select data following this text string and then output th data to a file.

    Can this be easily done in C++. If so, could someone point me in the right direction as to what commands I should look to use.

    I await you reply with interest.

    Chris Bayne

  2. #2
    C / C++
    Join Date
    Jan 2006
    The Netherlands
    You should learn basic C++ first, if you've never looked at C++ before. Why do you want to use C++ for this?
    Operating Systems:
    - Ubuntu 9.04
    - XP

    Compiler: gcc

  3. #3
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    The edge of the known universe
    It could be easily done in perl.

    It might also be easily done in python, or ruby(?)

    $ perl -n -e 'print "$1\n" if ( /match([0-9]+)/ );'
    The match is whatever uniquely identifies the prefix text
    The ([0-9]+) is whatever uniquely identifies the text you want to print

    Interactive Example
    hello world
    this doesn't match
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Newbie homework help
    By fossage in forum C Programming
    Replies: 3
    Last Post: 04-30-2009, 04:27 PM
  2. Replies: 8
    Last Post: 04-25-2008, 02:45 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 09:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM