Generate lines in vi editor

When you need to add multiple similar records to a configuration file (IP addresses for example), you may use vi editor to do it directly:

 :r! for i in $(seq 1 5); do echo "This is line \#${i}"; done

This command wil generate 5 lines:

This is line #1
This is line #2
This is line #3
This is line #4
This is line #5

Similar command used to generate Reverse DNS entries in BIND:

 :r! for i in $(seq 1 5); do echo "$i PTR host${i}.domain.com"; done
1 PTR host1.domain.com
2 PTR host2.domain.com
3 PTR host3.domain.com
4 PTR host4.domain.com
5 PTR host5.domain.com

Line numbers can be changed, modifyng the $(seq 1 5); part.

Leave a Reply

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