I have data in multiple text files that look like this:
1 DAEJ X -3120041.6620 -3120042.0476 -0.3856 0.0014
Y 4084614.2137 4084614.6871 0.4734 0.0015
Z 3764026.4954 3764026.7346 0.2392 0.0014
HEIGHT 116.0088 116.6419 0.6332 0.0017 0.0017 8.0
LATITUDE 36 23 57.946407 36 23 57.940907 -0.1699 0.0013 0.0012 57.5 0.0012 62.9
LONGITUDE 127 22 28.131395 127 22 28.132160 0.0190 0.0012 0.0013 2.3 0.0013
and I want to run it through a filter so that the output will look like this:
DAEJ: 36 23 57.940907, 127 22 28.132160, 116.6419
I can do it easily enough with grepWin using named capture by searching for:
(?<site>\w\w\w\w+)<filler>\r\n\r\n<filler>(?<height>\-?\d+\.\d+)<filler>(?<heightRMS>\d+\.\d+)<filler>\r\n<filler>(?<lat>\-?\ *\d+\ +\d+\ +\d+\.\d+)<filler>(?<latRMS>\d+\.\d+)<filler>\r\n<filler>(?<lon>\-?\ *\d+\ +\d+\ +\d+\.\d+)<filler>(?<lonRMS>\d+\.\d+)<filler>
and repacing with (ignore the unreferenced groups, I’ll use that in other implementations):
$+{site}: $+{lat}, $+{lon}, $+{height}
but of course, at the cost of doing it manually through a GUI. I was wondering if there’s a way to script it by piping pcregrep output to sed for text substitution? I’m aware of the pcregrep -M option to match the multiline regex pattern above, and I’ve been successful until that point, but I’m stuck with the sed end of the problem.
I would be using
awkto handle your text file:Broken out on multiple lines for readability:
Results:
EDIT:
Put the following code in a file called
script.awk:Run like this: