Loading ...
Sorry, an error occurred while loading the content.

49774Re: comma-separated fields - conversion, 1 line to N

Expand Messages
  • gumnos (Tim Chase)
    Apr 30, 2004
      > A friend of mine asked me how to convert file with these fields:
      > country,code1,code2,...,codeN
      > into
      > country,code1
      > country,code2
      > ...
      > country,codeN
      [snip]
      > How to do it in vim ?

      It looks like a substitute along the lines of

      s/\(COUNTRY\s*,\s*CODE\)\s*,\s*/\1^M/g

      would do the trick where:

      COUNTRY is a regex that finds countries
      (eg. "[^,]*" may be sufficient)
      CODE is the same sort of thing, finding codes
      (again, "[^,]*" may suffice)
      ^M is entered with ctrl+V followed by ctrl+M
      (I think you can use <cr> or \n here
      instead, but I never remember which
      one works, so I use the ^V^M method)

      -tim
    • Show all 8 messages in this topic