[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Jul 2008
]
[edlug] Regular Expression Substitution
Hey all.
Sorry to ask what is blatantly a work question, especially at this time
of a Friday but...
I've been asked to write a script that takes as it's arguments two
files. These files contain the same number of entries, and I need to
substitute part of one file into sections of the first.
I think I can get regular expressions to do this sort of substitution.
Write a regexp that can match each record in the file and substitute the
parts ($1 $2 etc?) of the matching regexp.
So, the two problems I have are...
1 - How can I substitute over different files. Essentially I want to run
parallel searches through the two files and each match in the first file
will have a corresponding match in the second file. These matches will
also have to be different patterns. I'm not sure if this is even possible.
2 - Parts of the first file are binary. Not the fields I'm after, but
the records are not one per line, like the second file. The first file
is the one to be changed using entries from the second file. So, while
there should be an equal number of regexp matches in each file, there
will not be an equal number of lines.
I'm writing a shell script for this and thought awk, sed, grep et al
might be the way to fo, but this late on a Friday my brain in a mess. I
hope this email makes sense to somebody and that that person can at
least point me in the right direction.
While I'm waiting for an answer to this I'll read up of regular
expressions again and try to at least get expressions that can match the
bits of the files I need, then I'll worry about the merger.
Cheers for any help you can give.
Martin Fraser...
-
----------------------------------------------------------------------
You can find the EdLUG mailing list FAQ list at:
http://www.edlug.org.uk/list_faq.html