how to search the pattern from the given file

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • rasmidas
    New Member
    • Jun 2007
    • 56

    how to search the pattern from the given file

    I have a text file. I need to search for two strings and replace the string for values from another line. I am attaching the text file.

    The requirement is like below:

    For every :61: line it will search for NOREF or NONREF string,
    if anyone of these exist, this string (NOREF/NONREF) will be replaced with the string in :86: line (the only :86: line that follows :61: line) OUR REF and YOUR REF which is in bold and italic in the below example. like below NOREF will be replaced by 031CHO090928100 268/9000022276

    Example:
    :61:090925C146, 00NTRFNOREF
    :86:051?00UEBER WEISUNG?109696/405?20OUR REF: 031CHO090928100 268?2
    1YOUR REF: 9000022276?22DEUTSCHE BANK AG FILIALE WI?23ESBADEN W
    ILHELMSTR. 20-22 /?24DEUTSCHE BANK AG ZENTRALE F?25RANKFURT DB-
    CHEQUE (EUROPE)?26M*PO FAV Y/DEUTDEFF510?27Z GR: RETURN OF A CHE
    QUE 111


    Please help me in doing this. The text file to be processed has been attached.
    Thanks in advance.

    Regards,
    Rasmi
  • Frinavale
    Recognized Expert Expert
    • Oct 2006
    • 9749

    #2
    Sounds like a job for regular expressions.
    Are you familiar with them?

    -Frinny

    Comment

    • numberwhun
      Recognized Expert Moderator Specialist
      • May 2007
      • 3467

      #3
      Originally posted by rasmidas
      I have a text file. I need to search for two strings and replace the string for values from another line. I am attaching the text file.

      The requirement is like below:

      For every :61: line it will search for NOREF or NONREF string,
      if anyone of these exist, this string (NOREF/NONREF) will be replaced with the string in :86: line (the only :86: line that follows :61: line) OUR REF and YOUR REF which is in bold and italic in the below example. like below NOREF will be replaced by 031CHO090928100 268/9000022276

      Example:
      :61:090925C146, 00NTRFNOREF
      :86:051?00UEBER WEISUNG?109696/405?20OUR REF: 031CHO090928100 268?2
      1YOUR REF: 9000022276?22DEUTSCHE BANK AG FILIALE WI?23ESBADEN W
      ILHELMSTR. 20-22 /?24DEUTSCHE BANK AG ZENTRALE F?25RANKFURT DB-
      CHEQUE (EUROPE)?26M*PO FAV Y/DEUTDEFF510?27Z GR: RETURN OF A CHE
      QUE 111


      Please help me in doing this. The text file to be processed has been attached.
      Thanks in advance.

      Regards,
      Rasmi
      Frinny is correct, you are going to have to use Regular Expressions for this. In fact, if you are not familiar with them, then what you are asking is going to be a bit difficult to understand at first.

      If the "86" data is on the next line as you show in your example, then the only way you are going to be able to grab from it what you need is to maybe do something like a look-ahead match to get what you need, then replace the "NO[N]REF" piece with the match.

      I would really recommend you get an excellent tutorial on Regex's if you don't know them yet, plus one of the plethora of cheat sheets around.

      Regards,

      Jeff

      Comment

      Working...