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
精彩评论