l i n u x - u s e r s - g r o u p - o f - d a v i s
L U G O D
 
Next Meeting:
October 7: Social gathering
Next Installfest:
TBD
Latest News:
Aug. 18: Discounts to "Velocity" in NY; come to tonight's "Photography" talk
Page last updated:
2005 Apr 22 00:43

The following is an archive of a post made to our 'vox-tech mailing list' by one of its subscribers.

Report this post as spam:

(Enter your email address)
Re: [vox-tech] simple parsing of multiple-line records...?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [vox-tech] simple parsing of multiple-line records...?



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@newbreedsoftware.com      Tonight's Forecast: Dark. Continued darkness
http://newbreedsoftware.com/   until widely scattered light in the morning.
_______________________________________________
vox-tech mailing list
vox-tech@lists.lugod.org
http://lists.lugod.org/mailman/listinfo/vox-tech



LinkedIn
LUGOD Group on LinkedIn
Sign up for LUGOD event announcements
Your email address:
facebook
LUGOD Group on Facebook
'Like' LUGOD on Facebook:

Hosting provided by:
Sunset Systems
Sunset Systems offers preconfigured Linux systems, remote system administration and custom software development.

LUGOD: Linux Users' Group of Davis
PO Box 2082, Davis, CA 95617
Contact Us

LUGOD is a 501(c)7 non-profit organization
based in Davis, California
and serving the Sacramento area.
"Linux" is a trademark of Linus Torvalds.

Sponsored in part by:
O'Reilly and Associates
For numerous book donations.