473,327 Members | 2,065 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,327 software developers and data experts.

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 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
2 1639
Frinavale
9,735 Expert Mod 8TB
Sounds like a job for regular expressions.
Are you familiar with them?

-Frinny
Nov 25 '09 #2
numberwhun
3,509 Expert Mod 2GB
@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

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

Similar topics

8
by: Sharif T. Karim | last post by:
I am trying to do the following with my search script that looks for records in a mysql table. The following is an example of what I am trying to do. Text being searched: -- The brown fox...
11
by: Ben | last post by:
Greetings, I am looking for a way to search for and delete files based on a pattern mask. For example, the search method would find all files matching a certain pattern containing wildcards (e.g....
10
by: Case Nelson | last post by:
Hi there I've just been playing around with some python code and I've got a fun little optimization problem I could use some help with. Basically, the program needs to take in a random list of no...
60
by: Julie | last post by:
What is the *fastest* way in .NET to search large on-disk text files (100+ MB) for a given string. The files are unindexed and unsorted, and for the purposes of my immediate requirements, can't...
1
by: Eric | last post by:
Hi: I have two files. I search pattern ":" from emails text file and save email contents into a database. Another search pattern " field is blank. Please try again.", vbExclamation + vbOKOnly...
2
by: beersa | last post by:
Hi All, I am looking for fastest search alogrithm in vb.net or vb2005. I write a code in vb2005 to find a string in given text file. The text file contains about 120,000 lines and search string...
4
by: Daryl Lee | last post by:
I am trying to locate all lines in a suite of files with quoted strings of particular lengths. A search pattern like r'".{15}"' finds 15-character strings very nicely. But I have some very long...
3
by: mercuryshipzz | last post by:
#!/usr/bin/perl #use strict; use warnings; sub search_pattern { my $file_name = $_;
4
by: mpatharkar | last post by:
Hi all, I wrote a script to search a pattern in input file and if pattern does not found in input file ,print that pattern in to output file. The input file is...
1
by: mravik | last post by:
Hi All, I have different subsystems in my application, if one is down it will through some error message in log file. I have a collection of error messages in another file and I want to check each...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.