[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Edlug Archive Jul 2008 ]

Re: [edlug] Regular Expression Substitution




The value in file 1 will more than likely not be unique. There is no comparison between the files. All I know so far is that the first record in one file should be substituted in the other.


I had thought about generating matches fro the second file, then running sed over the first to substitute in those matches, which would be a two pass approach, but I'm not sure how to get sed to do that in practice.

Thanks for the suggestion though.

mdf...

Andrew Neil Ramage wrote:

Why not do it in two stages ? First generate a sed file from file 2 :


{
   s/file1.value/file2.value;
   ...
}

then run sed on file 1 using this file as the input ?

Andrew

Martin Fraser wrote:

Thanks to those that answered. I've been fighting on with this so I'll clarify what I'm up to.


We have two files, outputted from different processes. File 2 contains the result of processing File 1. Each file contains position data in the form of Eastings and Northings, i.e. 0000.00N, 0000.00E

File 2 has slightly different (more accurate) position data, and our client wants the File1 positions replaced by the File2 positions in File 1 so they can do further processing of that data.

The small binary headers to each line in File 1 are not a difficult problem, they are well specified and won't match any regular expression that gets the bits of the line I need, but since the line start markers are in binary, there are no carriage returns of line feeds in the file so a line by line comparison can't be done.

File 2 contains loads of extra information but each line that I'm interesting in starts with the letter S. I'm assuming there is going to be a one to one correlation between the two files so the first match in File 1 should be substituted for the first match in File 2 etc.

I've already written the (very complicated) regexp that matches the easting and northings in File 1 and, using sed, can substitute the values for place holders NNNNNN.00N and EEEEEEE.00E for example, so I can see in the output that I have matched the correct parts of the line. It is working perfectly, but I can't see a way to make the regexp substitutions come from a different file, or an array lookup or anything that isn't just the static replacements with back references.

I hope this makes things clearer and some perl or regexp guru out there can help. This is my first serious use of regular expressions so I might be missing something obvious, any push in the right direction will be much appreciated.

Cheers.

Martin...

-
----------------------------------------------------------------------
You can find the EdLUG mailing list FAQ list at:
http://www.edlug.org.uk/list_faq.html



- ---------------------------------------------------------------------- You can find the EdLUG mailing list FAQ list at: http://www.edlug.org.uk/list_faq.html

- ---------------------------------------------------------------------- You can find the EdLUG mailing list FAQ list at: http://www.edlug.org.uk/list_faq.html



This archive is kept by wibble+RM@xxx.xxx.xxx
Morpheux
HomePage