home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ferkel.ucsb.edu!ucsbcsl!engrhub!harley
- From: harley@engrhub.ucsb.edu (Harley Hahn,,,HAHN,personal)
- Newsgroups: comp.unix.questions
- Subject: Re: stripping ^M's
- Keywords: stripping,carriage returns
- Message-ID: <7450@ucsbcsl.ucsb.edu>
- Date: 22 Jan 93 04:17:57 GMT
- References: <dholle15.727423491@ursa> <C14B40.LMK@acsu.buffalo.edu> <C14GKu.18n@acsu.buffalo.edu>
- Sender: news@ucsbcsl.ucsb.edu
- Lines: 53
-
- In article <C14GKu.18n@acsu.buffalo.edu> lusardi@acsu.buffalo.edu (Christopher Lusardi) writes:
- >Sorry, line (3) should have a "q" for multiple control-M's per line:
- >
- >1)One way is to use: vi your-file
- >2)type: shift-key and a semi-colon (eg :)
- >3)type: %s/control-key with a v then type control-key with a m/q
- >4)type: shift-key and :
- >5)type: wq!
- >
- >Note: the two slashs in (3) are required.
-
- Actually, I think you mean to use "g" (global)
- at the end of the %s command, not "q".
-
- However, the solution is still not completely correct.
-
- Use this:
-
- :%s/
-
- (When you enter it, type a ^V (Ctrl-V) before the each (Ctrl-M).)
-
- You are replacing all occurrences of two ^M's at the end
- of a line, with nothing:
-
- : --> the following is an ex command
- % --> carry out operation over all lines in the editing buffer
- s --> substitute
- / --> beginning of pattern to be replaced
- ^M^M --> two ^M's
- $ --> at the end of a file
- / --> beginning of replacement text
- / --> end of replacement text
-
- Note that you do not need to add "g" to the end of the command.
- A suffix of "g" is best used when the pattern to be replaced
- will occur in more than one place in the line.
- When you know where the pattern will be (in this case,
- at the end of the line) it is best to
- specify the location exactly (in this case with a "$").
-
- If you need to delete 2 ^M's at the end of each line of
- a file many times, there are ways to make it easy
- so you don't have to type in the ex command each time,
- but I won't go into them here.
-
- -- Harley Hahn
-
- (Actually, I have a wonderful proof that this
- task can be carried out by a one-line Perl
- program that emulates a Turing machine but,
- unfortunately, there is not enough room in the margin
- for me to elaborate... :-)
-