T
T
taaadm2016-03-22 15:53:23
vim
taaadm, 2016-03-22 15:53:23

Not an easy task for vim?

In the pf config, I need to insert a line with network addresses from 192.168.101.0/24 to 192.168.125.0/24 separated by a comma.
Can this be done using only vi (vim)? Well, or a single line compound bash command?
Do it manually, generate a string with a script using excel, etc. do not suggest :)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
sim3x, 2016-03-22
@taaadm

$ for n in {101..125}; do echo -n 192.168.$n.0/24, ; done

192.168.101.0/24,192.168.102.0/24,192.168.103.0/24192.168.104.0/24,192.168.105.0/24,192.168.107.0/24.192.168.107.0/24,192.168.10.0/24.192.168.10.0/24,192.168.10.0/24,192.168.10.0/24,192.168.12.0/24,192.168.112.0/24,192.168.12.0/24,192.168. 113.0 / 24,192.168.114.0 / 24,192.168.115.0 / 24,192.168.116.0 / 24,192.168.117.0 / 24,192.168.119.0 / 24,192.168.120.0 / 24,192.168.12.0 / 24,192.168.122.0 / 24,192.168.122.0 / 24,192.168.123.0 / 24,192.168.124.0 / 24,192.168.125.0 / 24,192.168,245.0 24,

A
abcd0x00, 2016-03-23
@abcd0x00

In Emacs, it's elementary.
You insert the initial line, go to the next line and turn on the macro recording.
You write a macro:
1. insert a line
2. move three words to the left
3. select a word
4. run the built-in calculator with zero argument
5. add one
6. turn off the calculator
7. return to the beginning of the line
8. select the line to the end
9. copy the line
10. go to the next line
Then you run this macro and it writes each time on a new line. When you get to 125, you stop and go to the last line.
Then you just glue the lines with a space to the very top.
Then you just replace spaces with commas until the end of the buffer.
It all takes me 20 seconds (if not in a hurry) from inserting the first row to getting the final list.
Vim probably has it all too. It's better to get used to macros, because it's lucky here that the script can be easily written, since the lines do not differ much. And it happens that you need to select some parts from the html source that are not always exactly defined.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question