deleting csv columns

deleting csv columns

1
NewbieNewbie
1

    Jan 25, 2007#1

    I've read some other column posts and met my basic needs. But I'd like to know if I can do it faster.

    I want to:
    1. open a csv file
    2. delete the first 3 columns
    3. keep column 4
    4. delete the columns after column 4

    I've accomplished this by converting to fixed width columns, then doing two deletes. Do I have to convert to fixed width? Can't I delete variable length columns?

    Thanks

    344
    MasterMaster
    344

      Jan 25, 2007#2

      The following Unix style regular expression does the job:

      replace:
      ^.*\,.*\,.*\,(.*),.*$
      with:
      \1

      or - even better - if you prefer the Perl-regexp-style:
      replace:
      ^.*?\,.*?\,.*?\,(.*?),.*
      with:
      $1

      ^ means: Start of line (might be omitted here)
      ? means: non-greedy, just up to the NEXT Komma.
      () means: my first variable = $1
      .* means: all characters

      Code: Select all

      next, columns, stays,BECAUSEITS4, IM, gonna, be, deleted, too

      Code: Select all

      BECAUSEITS4
      rds Bego

        Aug 01, 2008#3

        I found a smarter, more readable(?) approach. Here is it in a macro, you can "extract" the find/rep from there:
        The macro is called "delCol7":

        Code: Select all

        InsertMode
        ColumnModeOff
        HexOff
        PerlReOn
        Find RegExp "^(([^;]*;){6})[^;]*;"
        Replace All "$1"
        Normally using all newest english version incl. each hotfix. Win 10 64 bit