home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / unix / question / 15845 < prev    next >
Encoding:
Internet Message Format  |  1993-01-22  |  2.1 KB

  1. Path: sparky!uunet!ferkel.ucsb.edu!ucsbcsl!engrhub!harley
  2. From: harley@engrhub.ucsb.edu (Harley Hahn,,,HAHN,personal)
  3. Newsgroups: comp.unix.questions
  4. Subject: Re: stripping ^M's
  5. Keywords: stripping,carriage returns
  6. Message-ID: <7450@ucsbcsl.ucsb.edu>
  7. Date: 22 Jan 93 04:17:57 GMT
  8. References: <dholle15.727423491@ursa> <C14B40.LMK@acsu.buffalo.edu> <C14GKu.18n@acsu.buffalo.edu>
  9. Sender: news@ucsbcsl.ucsb.edu
  10. Lines: 53
  11.  
  12. In article <C14GKu.18n@acsu.buffalo.edu> lusardi@acsu.buffalo.edu (Christopher Lusardi) writes:
  13. >Sorry, line (3) should have a "q" for multiple control-M's per line:
  14. >
  15. >1)One way is to use:     vi your-file
  16. >2)type:       shift-key and a semi-colon (eg :)
  17. >3)type:       %s/control-key with a v then type control-key with a m/q
  18. >4)type:       shift-key and :
  19. >5)type:       wq!
  20. >
  21. >Note: the two slashs in (3) are required.
  22.  
  23. Actually, I think you mean to use "g" (global)
  24. at the end of the %s command, not "q".
  25.  
  26. However, the solution is still not completely correct.
  27.  
  28. Use this:
  29.  
  30. :%s/
  31.  
  32. (When you enter it, type a ^V (Ctrl-V) before the each (Ctrl-M).)
  33.  
  34. You are replacing all occurrences of two ^M's at the end
  35. of a line, with nothing:
  36.  
  37. :     --> the following is an ex command
  38. %     --> carry out operation over all lines in the editing buffer
  39. s     --> substitute
  40. /     --> beginning of pattern to be replaced
  41. ^M^M  --> two ^M's
  42. $     --> at the end of a file
  43. /     --> beginning of replacement text
  44. /     --> end of replacement text
  45.  
  46. Note that you do not need to add "g" to the end of the command.
  47. A suffix of "g" is best used when the pattern to be replaced
  48. will occur in more than one place in the line.
  49. When you know where the pattern will be (in this case,
  50. at the end of the line) it is best to
  51. specify the location exactly (in this case with a "$").
  52.  
  53. If you need to delete 2 ^M's at the end of each line of
  54. a file many times, there are ways to make it easy
  55. so you don't have to type in the ex command each time,
  56. but I won't go into them here.
  57.  
  58. -- Harley Hahn
  59.  
  60. (Actually, I have a wonderful proof that this
  61. task can be carried out by a one-line Perl
  62. program that emulates a Turing machine but,
  63. unfortunately, there is not enough room in the margin
  64. for me to elaborate... :-)
  65.