To search for text in file and then returns the two lines following it

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ray C
    New Member
    • Oct 2011
    • 1

    #1

    To search for text in file and then returns the two lines following it

    Hoping someone can help on this one. Have got some great information here.

    I need to search a text for for the string "Read {"

    When found I then need to return the two line following it.

    So...... text is
    Read {
    inputs 0
    file Q:/path/path/file.png

    I can find the string "Read {"
    but not sure how to return the two lines aftetr it.
    Actually want I want is the file path but only as they apply to "Reads" not other things in the file.



    file Q:/path/path/file.png
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Iterate on the file object: for line in fileObj:

    If the target text is in line, return the next 2 lines:
    Code:
    return fileObject.readline(), fileObject.readline()
    Last edited by bvdet; Nov 2 '11, 02:15 PM.

    Comment

    • srikanthtullimi
      New Member
      • Nov 2011
      • 1

      #3
      i didn't get please reply once again.

      Comment

      • bvdet
        Recognized Expert Specialist
        • Oct 2006
        • 2851

        #4
        srikanthtullimi ,

        What is it you did not get?

        Comment

        Working...