Xref: utzoo comp.unix.questions:31039 comp.lang.perl:5203 Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!usc!cs.utexas.edu!uwm.edu!linac!att!ucbvax!iwarp.intel.com!news From: merlyn@iwarp.intel.com (Randal L. Schwartz) Newsgroups: comp.unix.questions,comp.lang.perl Subject: Re: novice sed ? Message-ID: <1991May5.140740.12908@iwarp.intel.com> Date: 5 May 91 14:07:40 GMT References: <1991May3.213550.17246@ge-dab.GE.COM> <1991May3.225202.29639@umbc3.umbc.edu> Sender: news@iwarp.intel.com Reply-To: merlyn@iwarp.intel.com (Randal L. Schwartz) Followup-To: comp.unix.questions Organization: Stonehenge; netaccess via Intel, Beaverton, Oregon, USA Lines: 46 In-Reply-To: rouben@math16.math.umbc.edu (Rouben Rostamian) In article <1991May3.225202.29639@umbc3.umbc.edu>, rouben@math16 (Rouben Rostamian) writes: | In article <1991May3.213550.17246@ge-dab.GE.COM> brooks@sundance7.dab.ge.com (Stephen Brooks) writes: | > I have a sed question for you gurus: assume I have a file of the form | > | >name1; A1.1 B10.20 C100.300, | > D101.25 E202.50, | > F300.7 | >name2; Z44.33 Y409.45 | >name3; X777.77 W6.6, | > V32.15 | > | >where a comma (,) represents a continuation character. I need to "massage" | >this into something which looks like this: | > | >name1; A1.1 B10.20 C100.300 D101.25 E202.50 F300.7 | >name2; Z44.33 Y409.45 | >name3; X777.77 W6.6 V32.15 | > | >Can I do this in sed? | | Yes. Here it is: | | sed -n ' | :loop | /,$/{N | bloop | } | s/,\n//g | s/ */ /g | p' ; s/,\s*\n\s*/ /;}' out (which means, while you see a comma at the end of the line (ignoring trailing whitespace), append the next input line, and replace the comma, optional whitespace, newline, and more optional whitespace with a single space.) print "Just another Perl hacker," -- /=Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ==========\ | on contract to Intel's iWarp project, Beaverton, Oregon, USA, Sol III | | merlyn@iwarp.intel.com ...!any-MX-mailer-like-uunet!iwarp.intel.com!merlyn | \=Cute Quote: "Intel: putting the 'backward' in 'backward compatible'..."====/