Wednesday, March 19, 2003

Removing ^M's from text

(Using Vi) The only hard part about this is figuring out the proper key combination to generate the regular expression. To remove the ^M's, type:

:1,$s/^M//g

or

:%s/^M//g

where:

  • "1,$" or "%" designates "do the following to the whole file"
  • "^M" is generated by hitting "Control-V Control-M" (that's a capital V and M)
  • "g" signifies "perform the substitution with every matching instance in each line"

Source: alt.unix.wizards newsgroup

No comments:

Post a Comment