Path: utzoo!attcan!uunet!littlei!omepd!merlyn From: merlyn@iwarp.intel.com (Randal Schwartz) Newsgroups: comp.unix.wizards Subject: Re: vi and sed questions Message-ID: <4962@omepd.UUCP> Date: 22 Sep 89 19:31:40 GMT References: <4370002@hpavla.HP.COM> Sender: news@omepd.UUCP Reply-To: merlyn@iwarp.intel.com (Randal Schwartz) Organization: Stonehenge; netaccess via Intel, Hillsboro, Oregon, USA Lines: 31 In-reply-to: rowland@hpavla.HP.COM (Fred Rowland) In article <4370002@hpavla.HP.COM>, rowland@hpavla (Fred Rowland) writes: | vi question [...] | Example: | lastname firstname middlename @address@ ... | can be changed to | firstname middlename lastname @address@ ... | by this key mapping: | :map ` 0dwf$P(CTRL-V)(Return) | Just start at line 1, hold ` down, and watch the fun. | But there ought to be a better way. Entirely within vi: :g/^\([^ ][^ ]*\) *\([^ ][^ ]* *[^ ][^ ]*\)/s//$2 $1/ or cheating with (some versions of) AWK, :%|awk '{ tmp = $1; $1 = $2; $2 = $3; $3 = tmp; print }' or cheating with Perl (of course!), :%|perl -pe 's/^(\w+)\W+(\w+\W+\w+)/$2 $1/;' Just another hacker, (but why is this in unix.WIZARDS dudes?) -- /== Randal L. Schwartz, Stonehenge Consulting Services (503)777-0095 ====\ | on contract to Intel, Hillsboro, Oregon, USA | | merlyn@iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn | \== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/