vi and sed questions
Randal Schwartz
merlyn at iwarp.intel.com
Sat Sep 23 05:31:40 AEST 1989
In article <4370002 at hpavla.HP.COM>, rowland at 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 at iwarp.intel.com ...!uunet!iwarp.intel.com!merlyn |
\== Cute Quote: "Welcome to Oregon... Home of the California Raisins!" ==/
More information about the Comp.unix.wizards
mailing list