开发者

Replace commas with a tabbed space in many files

I'm trying to find a way to replace开发者_Python百科 commas , with a tabbed space \t or, in fact, it can be a single space as well. I would like to do this using BASH, and I was wondering perhaps Vim can accomplish such tasks?

I know I can do this manually or through command line for one file with:

vi [file] -c :%s/\,/\t/g

Would it be possible to do this on a loop of files, such as:

for i in *; do [vi command here]; done

Thanks for your help


tr is probably a better bet than vi for this task:

for i in *
do
   cat $i | tr ',' '\t' > $i.tmp
   mv $i.tmp $i
done


not exactly vi, but I think more appropriate

for f in * ; do sed -i -e 's/,/\t/g' $f ; done

Will for with vi as well (as in your sample). But the shorter way is

sed -i -e 's/,/\t/g' *


Yes, vim can do exactly that quite well. One trick is to start it as ex instead of vim. It's the same program, ex is just a link to vim, but when started as ex it comes up in the CLI instead of the screen mode.

so ross$ for i in /tmp/f?; do
> ex $i << \eof
> g-,-s// /g
> x
> eof
> done
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜