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

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

Expand Messages
  • Arun Easi
    Apr 30, 2004
    • 0 Attachment
      :s/\%(\(country,\)code\d*.*\)\@<=,\(code\d*\)/\r\1\2/g

      I thought, the last comma before 'code' is not required; but apparently
      did not do the job without it. If you have country1, country2, you could
      try this:

      :s/\%(\(country\d*,\)code\d*.*\)\@<=,\(code\d*\)/\r\1\2/g

      Of course, you need vim6.0+ (I guess) for this to work.

      regards,
      -Arun

      On Fri, 30 Apr 2004, Jacob Lerner wrote:

      > Hello,
      >
      > A friend of mine asked me how to convert file with these fields:
      > country,code1,code2,...,codeN
      > into
      > country,code1
      > country,code2
      > ...
      > country,codeN
      >
      > N is variable in each line. FIelds are comma-separated.
      > I gave him awk solution
      > awk -F, '{country=$1; for(i=2; i<=NF; i++) print $1 " " $(i); }'
      > but he doesn't have awk or perl (Win2k)
      >
      > How to do it in vim ?
      >
      > Yakov
      >
    • Show all 8 messages in this topic