home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / editors / 2008 < prev    next >
Encoding:
Text File  |  1992-08-16  |  1.2 KB  |  49 lines

  1. Newsgroups: comp.editors
  2. Path: sparky!uunet!decwrl!csus.edu!netcom.com!kemnitz
  3. From: kemnitz@netcom.com (Greg Kemnitz)
  4. Subject: Re: Switching fields in vi
  5. Message-ID: <p58mhnm.kemnitz@netcom.com>
  6. Date: Sun, 16 Aug 92 21:26:41 GMT
  7. Organization: Netcom - Online Communication Services  (408 241-9760 guest) 
  8. References: <1992Aug12.013235.28265@nuscc.nus.sg>
  9. Lines: 38
  10.  
  11. In article <1992Aug12.013235.28265@nuscc.nus.sg> ccechk@nuscc.nus.sg (Heng Kek) writes:
  12. =Hello everyone
  13. =
  14. =In my file, I have 2 columns of corresponding data, e.g.:
  15. =
  16. =name1    num1
  17. =name2     num2
  18. =name3    num3
  19. = :    :
  20. =namen    numn
  21. =
  22. =Question:  What's the best way to switch the 2 cols in vi?
  23. =I.e. to 
  24. =
  25. =num1    name1
  26. =num2     name2
  27. =etc
  28. =
  29. =Further to this problem, how does one switch cols given an arbitrary
  30. =number of columns to start with?  E.g. if I have 5 cols and I want
  31. =to switch cols 2 and 4, how do I do it?  I've thought about piping
  32. =the data through some one-line perl command from within vi, but
  33. =don't quite know how to begin.  I.e. something like '!G perl -e
  34. =...'.
  35. =
  36. =Thanks in advance for any responses.
  37. =
  38. =Kek
  39. =
  40. First answer,
  41.  
  42. !}awk '{print $2 " " $1}'
  43.  
  44.  
  45. Second answer,
  46.  
  47. !}awk '{print $1" "$4" "$3" "$2}'
  48.  
  49.