On 12/11/11 11:30, Guido Van Hoecke wrote:
Hi,

I want to edit a csv file with e.g. following content:

"tag2",2011/10/31,28250,28208,0,0,0.9985
"tag1",2011/10/31,1591,1583,8,0,1
"tag2",2011/10/30,15046,15008,0,0,0.9975
"tag1",2011/10/30,981,975,6,0,1
"tag2",2011/10/29,13019,12993,0,0,0.998
"tag1",2011/10/29,401,401,0,0,1
"tag2",2011/10/28,8687,8674,0,0,0.9985
"tag1",2011/10/28,1245,1233,12,0,1
"tag2",2011/10/27,8117,8108,0,0,0.9989
"tag1",2011/10/27,703,697,6,0,1
"tag2",2011/10/26,8327,8318,0,0,0.9989
"tag1",2011/10/26,496,496,0,0,1
"tag2",2011/10/25,0,0,0,0,0
"tag1",2011/10/25,973,971,2,0,1
"tag2",2011/10/24,0,0,0,0,0
"tag1",2011/10/24,823,823,0,0,1
"tag2",2011/10/23,0,0,0,0,0
"tag1",2011/10/23,1938,1936,2,0,1
"tag2",2011/10/22,0,0,0,0,0
"tag1",2011/10/22,968,968,0,0,1
"tag2",2011/10/21,0,0,0,0,0
"tag1",2011/10/21,526,526,0,0,1
"tag2",2011/10/20,0,0,0,0,0
"tag1",2011/10/20,828,828,0,0,1
"tag2",2011/10/19,0,0,0,0,0
"tag1",2011/10/19,1079,1079,0,0,1
"tag2",2011/10/18,0,0,0,0,0
"tag1",2011/10/18,850,849,1,0,1
"tag2",2011/10/17,0,0,0,0,0
"tag1",2011/10/17,2056,2056,0,0,1
"tag2",2011/10/16,0,0,0,0,0
"tag1",2011/10/16,1545,1542,3,0,1
"tag2",2011/10/15,0,0,0,0,0
"tag1",2011/10/15,1801,1783,18,0,1
"tag2",2011/10/14,0,0,0,0,0
"tag1",2011/10/14,1651,1644,5,0,0.9988
"tag2",2011/10/13,0,0,0,0,0
"tag1",2011/10/13,1785,1785,0,0,1
"tag2",2011/10/12,0,0,0,0,0
"tag1",2011/10/12,2071,2071,0,0,1

I want to get rid of all lines ending on 0,0,0,0,0
I want to replace all ',' by ';'
I want to replace all '.' by ','

With three individual commands, all is ok:

:%g/0,0,0,0,0/d
:%s/,/;/g
:%s/\./,/g

The end result is (as expected):
"tag2";2011/10/31;28250;28208;0;0;0,9985
"tag1";2011/10/31;1591;1583;8;0;1
"tag2";2011/10/30;15046;15008;0;0;0,9975
"tag1";2011/10/30;981;975;6;0;1
"tag2";2011/10/29;13019;12993;0;0;0,998
"tag1";2011/10/29;401;401;0;0;1
"tag2";2011/10/28;8687;8674;0;0;0,9985
"tag1";2011/10/28;1245;1233;12;0;1
"tag2";2011/10/27;8117;8108;0;0;0,9989
"tag1";2011/10/27;703;697;6;0;1
"tag2";2011/10/26;8327;8318;0;0;0,9989
"tag1";2011/10/26;496;496;0;0;1
"tag1";2011/10/25;973;971;2;0;1
"tag1";2011/10/24;823;823;0;0;1
"tag1";2011/10/23;1938;1936;2;0;1
"tag1";2011/10/22;968;968;0;0;1
"tag1";2011/10/21;526;526;0;0;1
"tag1";2011/10/20;828;828;0;0;1
"tag1";2011/10/19;1079;1079;0;0;1
"tag1";2011/10/18;850;849;1;0;1
"tag1";2011/10/17;2056;2056;0;0;1
"tag1";2011/10/16;1545;1542;3;0;1
"tag1";2011/10/15;1801;1783;18;0;1
"tag1";2011/10/14;1651;1644;5;0;0,9988
"tag1";2011/10/13;1785;1785;0;0;1
"tag1";2011/10/12;2071;2071;0;0;1

But I want to combine these three operations in one command:
:%g/0,0,0,0,0/d|%s/,/;/g|%s/\./,/g
but this gives following result:
"tag2";2011/10/31;28250;28208;0;0;0;9985
"tag1";2011/10/31;1591;1583;8;0;1
"tag2";2011/10/30;15046;15008;0;0;0;9975
"tag1";2011/10/30;981;975;6;0;1
"tag2";2011/10/29;13019;12993;0;0;0;998
"tag1";2011/10/29;401;401;0;0;1
"tag2";2011/10/28;8687;8674;0;0;0;9985
"tag1";2011/10/28;1245;1233;12;0;1
"tag2";2011/10/27;8117;8108;0;0;0;9989
"tag1";2011/10/27;703;697;6;0;1
"tag2";2011/10/26;8327;8318;0;0;0;9989
"tag1";2011/10/26;496;496;0;0;1
"tag1";2011/10/25;973;971;2;0;1
"tag1";2011/10/24;823;823;0;0;1
"tag1";2011/10/23;1938;1936;2;0;1
"tag1";2011/10/22;968;968;0;0;1
"tag1";2011/10/21;526;526;0;0;1
"tag1";2011/10/20;828;828;0;0;1
"tag1";2011/10/19;1079;1079;0;0;1
"tag1";2011/10/18;850;849;1;0;1
"tag1";2011/10/17;2056;2056;0;0;1
"tag1";2011/10/16;1545;1542;3;0;1
"tag1";2011/10/15;1801;1783;18;0;1
"tag1";2011/10/14;1651;1644;5;0;0;9988
"tag1";2011/10/13;1785;1785;0;0;1
"tag1";2011/10/12;2071;2071;0;0;1

Note that all 0.99 get changed into 0;99 rather than 0,99

Is this an error or do I hit some limitation in combining commands?

I have  hlsearch on, and at the end of this combined command all '.' characters
are highlighted when undoing the change. So the last thing searched was indeed
'.' and I do not understand why it seems to be replaced with ';'
rather than ','

Please advise.

TIA,


Guido.


As said under ":help :bar", the :g[lobal] command considers the | as part of its operands.

You ought to be able to do it with

        :exe '%g/0,0,0,0,0/d' | %s/,/;/g | %s/\./,/g

because wrapping the :g command inside :exe (which does not include the | in its operands) defines where :g ends and separates it from the |


Best regards,
Tony.
--
Two men came before Nasrudin when he was magistrate.  The first man
said, "This man has bitten my ear -- I demand compensation."  The
second man said, "He bit it himself."  Nasrudin withdrew to his
chambers, and spent an hour trying to bite his own ear.  He succeeded
only in falling over and bruising his forehead.  Returning to the
courtroom, Nasrudin pronounced, "Examine the man whose ear was bitten.
If his forehead is bruised, he did it himself and the case is
dismissed.  If his forehead is not bruised, the other man did it and
must pay three silver pieces."

--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

Reply via email to