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

hihihi
hahaha
hehehe

we will change the “hahaha” becomes “gagaga”

here’s what we do using vim

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

Now let’s see change that we’ve made

$ more sample.txt
hihihi
gagaga
hehehe

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 *