home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / unix / question / 10709 < prev    next >
Encoding:
Text File  |  1992-09-03  |  1.1 KB  |  42 lines

  1. Newsgroups: comp.unix.questions
  2. Path: sparky!uunet!cs.utexas.edu!torn!cunews!nrcnet0!bnrgate!bcars267!bcarh803!christo
  3. From: christo@bcarh803.BNR.CA (Mark Christopher)
  4. Subject: Re: awk with columns
  5. Message-ID: <1992Sep3.222416.12370@bnr.ca>
  6. Sender: news@bnr.ca (usenet)
  7. Nntp-Posting-Host: bcarh803
  8. Reply-To: christo@bnr.ca
  9. Organization: Bell-Northern Research Ltd.
  10. References:  <29098@hydra.Helsinki.FI>
  11. Date: Thu, 3 Sep 1992 22:24:16 GMT
  12. Lines: 28
  13.  
  14. In article <29098@hydra.Helsinki.FI>, karell@cs.Helsinki.FI (Esa Karell)
  15. writes:
  16. |>Could someone tell me what would be the easisest
  17. |>way to accomplish this with awk.
  18.  
  19. |>X    Y  T        P I
  20. |>1    2  3        4 5
  21.  
  22. |>I'd need to swap the values of Y & T so output should look:
  23. |>
  24. |>X    Y  T        P I
  25. |>1    3  2        4 5
  26. |>.    .  .        . .
  27. |>
  28. |>All the blanks between the columns should remain the same.
  29.  
  30. Well, what do you think?  Two easy ways:
  31.  
  32. Come up with a printf format string and say
  33.  
  34.     { printf "....format....",$1,$3,$2,$4,$5 }
  35.  
  36. or else find the column numbers and do:
  37.  
  38.     { print substr(..),substr(..),... }
  39.  
  40. -- 
  41. Mark Christopher        Bell-Northern Research          christo@bnr.ca
  42.