开发者

need help on sed and awk command?

INPUT FILE :

O,ff,$1123.81,ty,20100608,jjj,,13.180002,,,,

O,gg,$1794.06,jui,20100608,jjj,,13.180008,,,,

O,gg,$1794.06,jui,20100608,jjj,,13.180008,,,,

wh开发者_运维百科ere ever ,, occurs in the input file i need to replace with , ,(space between,,) could anyone please help me out on this?


A pure bash script

#!/bin/bash
# tested on bash 4

while read -r line
do
    while [[ $line =~ ,, ]]
    do
        line=${line//,,/, ,}
    done
    echo "$line"
done < file

Sample output

bash4> bash comma.sh
O,ff,$1123.81,ty,20100608,jjj, ,13.180002, , , ,
O,gg,$1794.06,jui,20100608,jjj, ,13.180008, , , ,
O,gg,$1794.06,jui,20100608,jjj, ,13.180008, , , ,

Note, that the extra while loop is used to change subsequent ,, to , ,


Something like this may work:

sed -e 's/,,/, ,/g' inputfile

As bash-o-logist points out, the desired result for things like ,,,, might be , , , ,. If so then this could be used (run the command twice):

sed -e 's/,,/, ,/g; s/,,/, ,/g' inputfile
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜