By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
437,660 Members | 1,299 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 437,660 IT Pros & Developers. It's quick & easy.

how to search the pattern from the given file

P: 56
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 031CHO090928100268/9000022276

Example:
:61:090925C146,00NTRFNOREF
:86:051?00UEBERWEISUNG?109696/405?20OUR REF: 031CHO090928100268?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?27ZGR: 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
Nov 16 '09 #1
Share this Question
Share on Google+
2 Replies


Frinavale
Expert Mod 5K+
P: 9,731
Sounds like a job for regular expressions.
Are you familiar with them?

-Frinny
Nov 25 '09 #2

numberwhun
Expert Mod 2.5K+
P: 3,503
@rasmidas
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
Nov 25 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.