1

I couldn't find any reasonable answer for my specific question; I know how to deal with search of replace of the vim/sed, but how do we deal with csv in vim regarding the column mode search and replace. i.e. we have chunk of data in csv as :

automotive_bitcount,1,1,0,1,0,0,0,0,1,0,0,1,1,0,1,0,1,1,1,1,0,0,1,0,0
automotive_bitcount,1,0,0,1,0,1,0,1,1,1,0,0,0,0,1,1,1,0,1,0,1,0,0,1,0
automotive_bitcount,2,1,0,0,0,0,1,0,1,0,1,1,0,0,0,0,0,0,1,1,1,1,0,1,0
automotive_bitcount,2,0,0,0,1,1,0,0,1,0,0,0,1,1,1,0,0,0,0,1,1,1,1,0,0
automotive_bitcount,2,1,0,0,0,1,1,0,1,0,1,1,0,0,1,1,1,0,1,1,1,0,1,1,1

which represents for the header:

APP_NAME, DATASET, COMPILER FLAGS#1,...,COMPILER FLAG#24

Here is the statement of the search and replace; I would like to replace those "1" in columns with the corresponding "Compiler flag options" (which I put down here) so at the nend I could have something like this structure in order to pass them to the compiler:

automotive_bitcount dataset1  -fno-guess-branch-probability -fno-ivopts -fno-tree-loop-optimize -fno-inline-functions  -fno-omit-frame-pointer -falign-jumps -fselective-scheduling  -fno-tree-pre  -fno-move-loop-invariants

Just for the record, the 24 compiler flags are as follows (in their orders):

compilerOptionList= "-funsafe-math-optimizations -fno-guess-branch-probability -fno-ivopts -fno-tree-loop-optimize -fno-inline-functions -funroll-all-loops -fno-omit-frame-pointer -falign-jumps -fselective-scheduling -fno-inline-small-functions -fno-tree-pre ftracer -fno-move-loop-invariants -O2 -fno-tree-ter -fprefethch-loop-arrays -max-unrolled-insns -fno-inline-functions-called-once -fno-cprop-registers -finline-functions -fno-schedule -fno-align-functions -fno-tree-dce -fno-merge-constants"
Amir
  • 1,348
  • 3
  • 21
  • 44
  • I definitely know, the main question is, How to I match the csv in column-wise mode ? `\%c`is only matching the column lines but not csv columns... and I think I exactly posted my problem t the point awhere I was struggling, certainly i know how to put those in a loop and get it done – Amir Nov 07 '13 at 14:54
  • 1
    You could try using Vim `split()` function on each line, which returns a List. The element 1 of this list will be your flag #1, 2 correspond to flag #2, and so on. – mMontu Nov 07 '13 at 15:01
  • Another option is use a `:s` command with a pattern that use 24 pairs of parenthesis to capture the values between the commas (possible with the aid of `repeat()`), and a map to substitute each of them, similar to what is explained [this answer.](http://stackoverflow.com/a/9080026/717124) If you have specific problems with these approaches (or any other you can think) and explain then it will be easier to provide meaningful answers. – mMontu Nov 07 '13 at 15:08

1 Answers1

5

The csv.vim - A Filetype plugin for csv files plugin has a substitute command that is scoped to a certain column:

:[range]Substitute [column/]pattern/string[/flags]
Ingo Karkat
  • 167,457
  • 16
  • 250
  • 324
  • tnx for the info, seems great, but after I installed and open my .csv it's been mentioned : `CSV Syntax:No filetype support, only simple highlighting using, as delimiter! See :h csv-installation CSV Syntax:Invalid column pattern, using default pattern \%([^,]*,\|$\)` – Amir Nov 07 '13 at 16:28
  • it seems that it doesn't recognize the functions that its being mentioned in the help file, keep complaining about unknown sysntax when I use the keyword `Substitute` – Amir Nov 07 '13 at 16:45
  • 2
    Put `:filetype plugin on` into your `~/.vimrc`. This is generally useful. – Ingo Karkat Nov 07 '13 at 16:46
  • buddy do u know if there is such plug-ins for bash sed as well ? In general what do you suggest ? – Amir Dec 12 '13 at 18:18
  • 1
    There are no plugins for sed; you can only use pre-canned scripts, or use Vim as a replacement for sed; see `:h -s-ex` in Vim. – Ingo Karkat Dec 13 '13 at 09:43