Search code examples
csvemacsemacs24

Emacs 24.5 : replace pattern in a specific column of a CSV file


I want to replace in the 3rd column ONLY the pattern 'foo' by 'bar' of the following CSV file. Is it possible to do this with emacs or do I need to write a script to do this ?

foo;bbb;foo;
foo;bbbbbbbb;bar;
foo;bbbbbb;foo;
foo;bbbbbbbbbbbb;bar;
foo;bbbbbb;foo;

So, the expedted result would be :

foo;bbb;bar;
foo;bbbbbbbb;bar;
foo;bbbbbb;bar;
foo;bbbbbbbbbbbb;bar;
foo;bbbbbb;bar;

Solution

  • With csv mode: https://github.com/emacsmirror/csv-mode

    M-x csv-transpose
    Then your column is a line, so you can select as region and do a query-replace on the region or use narrow-to-region or ...
    M-x csv-transpose
    
      -