[vox-tech] simple parsing of multiple-line records...?
Bill Kendrick
nbs at sonic.net
Thu Apr 21 23:35:54 PDT 2005
On Thu, Apr 21, 2005 at 11:20:39PM -0700, Dylan Beaudette wrote:
> Hi everyone,
>
> this might be a really simple question, but :
>
>
> i have a text file with multiple-line records in a format like this:
>
> ----------------------------
> easting: 661674.9375
> northing: 4035004.0000
> elevation: 968.8617
> distance along surface: 15.9540
>
> easting: 661683.7500
> northing: 4034946.7500
> elevation: 961.4768
> distance along surface: 58.4077
> -----------------------------
A silly way I can think of is to first convert all EOLs to some
special character (say, a "|"), then convert all double-|s to single EOLs.
Something like this in a shell:
cat foo.txt | tr \\n \| | sed s/\|\|/\\n/g
If I tack a "| sed s/\\t//g" at the end and run your above input, I get this:
easting:661674.9375|northing:4035004.0000|elevation:968.8617|distance along surface:15.9540
easting:661683.7500|northing:4034946.7500|elevation:961.4768|distance along surface:58.4077|
Which seems a bit more reasonable to parse. If the values are always in
the same place, hacking at it with 'cut' could even work:
... | tr \| : | cut -d ":" -f 2,4,6,8
Results in:
661674.9375:4035004.0000:968.8617:15.9540
661683.7500:4034946.7500:961.4768:58.4077
:)
Of course, the smarter folks around here will come up with a more
elegant solution, but I love trying to cram crazy problems into the
basic shell apps. :)
Good luck! I hope I helped SOMEwhat! ;)
--
-bill!
bill at newbreedsoftware.com Tonight's Forecast: Dark. Continued darkness
http://newbreedsoftware.com/ until widely scattered light in the morning.
More information about the vox-tech
mailing list