Note that there are some explanatory texts on larger screens.

plurals
  1. POFiltering multiline pcregrep match with sed
    text
    copied!<p>I have data in multiple text files that look like this:</p> <pre><code>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 </code></pre> <p>and I want to run it through a filter so that the output will look like this:</p> <pre><code>DAEJ: 36 23 57.940907, 127 22 28.132160, 116.6419 </code></pre> <p>I can do it easily enough with grepWin using named capture by searching for:</p> <pre><code>(?&lt;site&gt;\w\w\w\w+)&lt;filler&gt;\r\n\r\n&lt;filler&gt;(?&lt;height&gt;\-?\d+\.\d+)&lt;filler&gt;(?&lt;heightRMS&gt;\d+\.\d+)&lt;filler&gt;\r\n&lt;filler&gt;(?&lt;lat&gt;\-?\ *\d+\ +\d+\ +\d+\.\d+)&lt;filler&gt;(?&lt;latRMS&gt;\d+\.\d+)&lt;filler&gt;\r\n&lt;filler&gt;(?&lt;lon&gt;\-?\ *\d+\ +\d+\ +\d+\.\d+)&lt;filler&gt;(?&lt;lonRMS&gt;\d+\.\d+)&lt;filler&gt; </code></pre> <p>and repacing with (ignore the unreferenced groups, I'll use that in other implementations):</p> <pre><code>$+{site}: $+{lat}, $+{lon}, $+{height} </code></pre> <p>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 <code>pcregrep -M</code> option to match the multiline regex pattern above, and I've been successful until that point, but I'm stuck with the <code>sed</code> end of the problem.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload