search for text string in a file

This is a discussion on search for text string in a file within the C++ Programming forums, part of the General Programming Boards category; Hi there, I have a background as a mainframe programmer. Assembler, Cobol etc. Never looked a C++ before but I ...

  1. #1
    Registered User
    Join Date
    May 2007
    Posts
    1

    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
    Plymouth.

  2. #2
    C / C++
    Join Date
    Jan 2006
    Location
    The Netherlands
    Posts
    312
    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 wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,761
    It could be easily done in perl.

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

    Code:
    $ 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
    Code:
    hello world
    match1234
    1234
    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.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

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, 05:27 PM
  2. Replies: 8
    Last Post: 04-25-2008, 03:45 PM
  3. String issues
    By The_professor in forum C++ Programming
    Replies: 7
    Last Post: 06-12-2007, 10:11 AM
  4. Linked List Help
    By CJ7Mudrover in forum C Programming
    Replies: 9
    Last Post: 03-10-2004, 10:33 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21