home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.editors
- Path: sparky!uunet!decwrl!csus.edu!netcom.com!kemnitz
- From: kemnitz@netcom.com (Greg Kemnitz)
- Subject: Re: Switching fields in vi
- Message-ID: <p58mhnm.kemnitz@netcom.com>
- Date: Sun, 16 Aug 92 21:26:41 GMT
- Organization: Netcom - Online Communication Services (408 241-9760 guest)
- References: <1992Aug12.013235.28265@nuscc.nus.sg>
- Lines: 38
-
- In article <1992Aug12.013235.28265@nuscc.nus.sg> ccechk@nuscc.nus.sg (Heng Kek) writes:
- =Hello everyone
- =
- =In my file, I have 2 columns of corresponding data, e.g.:
- =
- =name1 num1
- =name2 num2
- =name3 num3
- = : :
- =namen numn
- =
- =Question: What's the best way to switch the 2 cols in vi?
- =I.e. to
- =
- =num1 name1
- =num2 name2
- =etc
- =
- =Further to this problem, how does one switch cols given an arbitrary
- =number of columns to start with? E.g. if I have 5 cols and I want
- =to switch cols 2 and 4, how do I do it? I've thought about piping
- =the data through some one-line perl command from within vi, but
- =don't quite know how to begin. I.e. something like '!G perl -e
- =...'.
- =
- =Thanks in advance for any responses.
- =
- =Kek
- =
- First answer,
-
- !}awk '{print $2 " " $1}'
-
-
- Second answer,
-
- !}awk '{print $1" "$4" "$3" "$2}'
-
-