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

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

Expand Messages
  • Arun Easi
    Thinking of it again, I see a more concise way: s/ v((country d*,).*)@
    Message 1 of 8 , Apr 30, 2004
      Thinking of it again, I see a more concise way:

      s/\v((country\d*,).*)@<=,/\r\2/g

      I realized that without the comma before the code (in the previous
      example), I would leave the comma there.

      hth,
      -Arun

      On Fri, 30 Apr 2004, Arun Easi wrote:

      > :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
      > >
      >
    • Jacob Lerner
      ... He s at odds with the sysadmin at work, and they don t allow him to install anything on w2k. Sad story. I wonder how he got vim installed. Yakov
      Message 2 of 8 , May 1 8:15 AM
        David Rock wrote:

        >* Suresh Govindachar <sgovindachar@...> [2004-04-30 17:06]:
        >
        >
        >>>doesn't have awk or perl (Win2k)
        >>>
        >>>
        >>which seems to imply that neither awk nor perl
        >>can be had on Win2K. I do know that perl
        >>can be had on Win2K, and suspect so can awk.)
        >>
        >>
        >
        >At a minimum, both can be gotten from cygwin, but that's a lot of
        >overhead just to get these two (but still worth it ;-)
        > http://www.cygwin.com
        >
        >Windows version of gawk:
        > http://gnuwin32.sourceforge.net/packages/gawk.htm
        >
        >Windows version of perl:
        > http://www.activestate.com/
        > or
        > http://www.cpan.org/ports/#win32
        >
        >
        >
        He's at odds with the sysadmin at work, and they don't allow him
        to install anything on w2k. Sad story. I wonder how he got vim installed.

        Yakov
      Your message has been successfully submitted and would be delivered to recipients shortly.