Using VIM as stream editor

Every person associated with the unix / linux would be familiar with the text editor called vi / vim. but not many people know that vi / vim can be used as a stream editor. This is one example of how to use vi / vim as a text editor. suppose we have a text file containing the following text:

sample.txt

1hihihi
2hahaha
3hehehe

we will change the “hahaha” becomes “gagaga”

here’s what we do using vim

1$ vim -b -c ":%s/hahaha/gagaga/g|:wq" sample.txt
2"sample.txt" 6L, 24C
3"sample.txt" 6L, 24C written

Now let’s see change that we’ve made

1$ more sample.txt
2hihihi
3gagaga
4hehehe

cool isn’t it? 🙂

2 Comments

  1. todd

    Great! So excited to know about this.

Leave a Reply

Your email address will not be published. Required fields are marked *