home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #18 / NN_1992_18.iso / spool / comp / unix / question / 10161 < prev    next >
Encoding:
Internet Message Format  |  1992-08-18  |  3.5 KB

  1. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!caen!nic.umass.edu!m2c!jjmhome!alden!alden.UUCP
  2. From: sgr@alden.UUCP (Stan Ryckman)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: problem with vi..
  5. Message-ID: <514@alden.UUCP>
  6. Date: 18 Aug 92 17:04:10 GMT
  7. References: <1992Aug17.155121.21926@njitgw.njit.edu> <2195@fnnews.fnal.gov>
  8. Sender: usenet@alden.UUCP
  9. Organization: Alden Electronics, Westboro, MA
  10. Lines: 79
  11.  
  12. In article <2195@fnnews.fnal.gov> shah@fnalb.fnal.gov writes:
  13. |>In article <1992Aug17.155121.21926@njitgw.njit.edu>, cxk6819@hertz.njit.edu (K. Chandrakanth) writes:
  14. |>|> Dear netters,
  15. |>|>      I have a sparc workstation 2.
  16. |>|> I mounted the floppy drive and copied few files from the floppy. But
  17. |>|> when I viewed through vi I happened to see ^M at the end of each line.
  18. |>|> When I cat the file it looks normal. Will some one tell me the reason
  19. |>|> for this. If possible please send me a shell script or small c program
  20. |>|> to remove this. I am enclosing a sample of the file.
  21. |>|> 
  22. |>|>     But when I compile the file it works fine. The control characters
  23. |>|> are really irritating. So help me.
  24. |>|> 
  25. |>|> struct employee {^M
  26. |>|>     e_type typer;^M
  27. |>|>     employee *next;^M
  28. |>|>     char name[20];^M
  29. |>|>     short department;^M
  30. |>|> };^M
  31. |>|> ^M
  32. |>|> struct manager:employee {^M
  33. |>|>         employee* group;^M
  34. |>|>         short level;^M
  35. |>|> };^M
  36. |>|> void print_emp(employee *);^M
  37. |>|> void f(employee *);^M
  38. |>|> void print_emp(employee *e)^M
  39. |>|> {^M
  40. |>|> 
  41. |>|> Please email to me. Thanks in advance...
  42. |>
  43. |>vi the file and type following vi command:
  44. |>
  45. |>:%s/^VM//g
  46.  
  47. Probably you meant ^V^M.
  48.  
  49. |>where '^V' is one character <Ctrl>V
  50.  
  51. I frequently get such files; in fact I prepare Usenet and Email
  52. responses at home on a PC and bring them back on a floppy.
  53. DOS lines end with the carriage return-linefeed (^M^J) sequence,
  54. whereas UNIX just uses ^J.  Hence, vi shows the "extra" ^M.
  55. One might think that "cat" doesn't, since the carriage return
  56. is invisible on the screen when followed by a linefeed (although
  57. "cat file1 > file2; vi file2" would show you that cat DOES actually
  58. pass the ^M characters).
  59.  
  60. The suggested command (with above fix) will work, but I use it so
  61. often that I put the following into my .login:
  62.     setenv EXINIT "map g G\
  63.     map \m :%s/^V^V^V^M//^M\
  64.     set ignorecase showmatch nu ai shiftwidth=4"
  65. The second line is the relevant one; the rest are just my
  66. preferred default choices.  I don't bother with "g" at the end of
  67. command, since there's never more than one ^M per line.  To enter
  68. this line into your .login using vi, you actually have to type:
  69. map \m :%s/^V^V^V^V^V^V^V^M//^V^M\
  70. i.e., one ^V escape for each control character you want, which
  71. includes ^V characters.
  72.  
  73. This mess sets up a vi macro which lets you type the two character
  74. sequence "\m" to get rid of all the ^M characters.  Advantage:
  75. once you get it right, you just leave it alone.  Note: normally,
  76. you have to type the "\" and "m" within about a second, or the
  77. "timeout" feature (unless you disable it, which you won't want
  78. to if you use function keys etc.) will assume the "\" was
  79. intended as a standalone command.  You can map it into some unused
  80. single vi character (such as "K"), or a function key, if you prefer
  81. that to "\m".
  82.  
  83. One other thing: if your files come from DOS originally, you
  84. may find a ^Z at the end.  (That's Bill Gates' idea of a joke,
  85. I think.)  You can kill that too.
  86.  
  87. Stan.
  88. --
  89. This .signature has expired.  Call 1-900-YOU-FOOL to find out why.
  90.     Stan Ryckman   sgr@alden.UUCP
  91.