我们怎样才能取代" ./."用" -1"

时间:2017-12-08 15:35:17

标签: sed replace

输入

7058    7067    7111    7186    7288    7322    7328    7373
./. ./. ./. ./. ./. 0|0 ./. 0|0
./. ./. 0|0 ./. ./. 0|0 ./. 0|0
./. ./. ./. ./. ./. 0|0 ./. 0|0
./. ./. ./. ./. ./. 0|0 ./. 1|1

期望的输出

7058    7067    7111    7186    7288    7322    7328    7373
-1  -1  -1  -1  -1  0|0 -1  0|0
-1  -1  0|0 -1  -1  0|0 -1  0|0
-1  -1  -1  -1  -1  0|0 -1  0|0
-1  -1  -1  -1  -1  0|0 -1  1|1

我尝试sed -i 's/././-1/g' File_name,但它没有用。

2 个答案:

答案 0 :(得分:1)

An expression for that:

sed -E 's,./.,-1,g' <(echo './.')

You can use delimiters different from /, so you don't have to escape them, . doesn't have to be excaped if you are using extended regular expressions.

Possible delimiters(there may be others):

  • :
  • _
  • ,
  • |

So in your case:

sed -E -i.backup 's,./.,-1,g' File_name

, or you are able to escape .-s and /-s, but that can lead to a mess:

sed -i.backup 's/\.\/\./-1/g' File_name

Please use an extension name after the i flag to make a backup file if you're not sure about the result of the sed command.

答案 1 :(得分:0)

    const WebSocket = require('ws');
    const ws = new WebSocket("wss://api.bitfinex.com/ws");

    const fs = require('fs');

    ws.onopen = function(){
        ws.send(JSON.stringify({'event':'subscribe', 'channel':'ticker', 'pair':'btcusd'}))
    };

    ws.onmessage = function(msg){ 

        var response = JSON.parse(msg.data); 
        if (response[1] !="hb"){
            console.log("Bitfin " + response[7]); 
            //HERE I need to update existing CSV file,
            //for example 
            //BTC,xxxx
            //ETH,xxxx
            //two columns, and n rows..
        }   
    };

=&GT; 7058 7067 7111 7186 7288 7322 7328 7373 -1 -1 -1 -1 -1 0 | 0 -1 0 | 0 -1 -1 0 | 0 -1 -1 0 | 0 -1 0 | 0 -1 -1 - 1 -1 -1 0 | 0 -1 0 | 0 -1 -1 -1 -1 -1 0 | 0 -1 1 | 1