まったりするmatayu

ツイートにゴミがついた感じのブログ

設定の生成

こんな感じの設定を大量に作る必要があった。

edit 1
    set srcintf "hoge"
    set dstintf "huga"
    set srcaddr "all"
    set dstaddr "piyo"
    set action accept
    set schedule "always"
    set service "ALL"
    set fixedport enable
next

editの部分を連番にする。

#!/usr/bin/perl

use strict;
use warnings;

for (my $edit = 1; $edit <= 100; $edit++){
  my $str = "
  edit $edit
    set srcintf \"hoge\"
    set dstintf \"huga\"
    set srcaddr \"all\"
    set dstaddr \"piyo\"
    set action accept
    set schedule \"always\"
    set service \"ALL\"
    set fixedport enable
  next
  ";
  print "$str\n";
}

これワンライナーでできるのかな。

ワンライナーのオプションども

  • l

入力の改行とって、出力に改行つける

  • e

パラメーターをプログラムとみなす

書いたやつ

perl -le 'map {print "edit $_"."\n    tset srcintf hoge
    set dstintf huga
    set srcaddr all
    set dstaddr piyo
    set action accept
    set schedule always
    set service ALL
    set fixedport enable
next"} 1..100'

ワンライナー...?