亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何將文件中的 IP 地址列表從 xxxx-xxxx 擴展為 xxxx-x 格式?

如何將文件中的 IP 地址列表從 xxxx-xxxx 擴展為 xxxx-x 格式?

MM們 2023-12-09 14:52:44
IP范圍10.0.0.1-10.0.0.3可擴展至10.0.0.110.0.0.210.0.0.3通過使用這個腳本eval printf '%s\\n' $(echo '10.0.0.1-10.0.0.3' | awk -F'[.-]' -v OFS='.' '{for(i=1;i<=4;i++) $i = "{" $i ".." $(i+4) "}"; NF=4} 1')但如果我有一組這樣的數據;10.0.0.1-10.0.0.3172.16.0.3192.168.0.2-192.168.0.2我如何產生這樣的輸出?10.0.0.110.0.0.210.0.0.3172.16.0.3192.168.0.2
查看完整描述

1 回答

?
天涯盡頭無女友

TA貢獻1831條經驗 獲得超9個贊

您能否嘗試以下操作,僅在 GNU 中使用所示示例進行編寫和測試awk。


awk '

BEGIN{

  FS="-"

  OFS="."

}

$1==$2 || NF==1{

  print $1

  next

}

{

  num1=split($1,arr1,".")

  num2=split($2,arr2,".")

  for(i=arr1[num1];i<=arr2[num2];i++){

     print arr1[1],arr1[2],arr1[3],i

  }

}' Input_file

說明:對上述內容添加詳細說明。


awk '                                     ##Starting awk program from here.

BEGIN{                                    ##Starting BEGIN section of this program from here.

  FS="-"                                  ##Setting field separator as - here. 

  OFS="."                                 ##Setting output field separator as . here.

}

$1==$2 || NF==1{                          ##Checking condition if 1st field is equal to 2nd field OR number of fields is 1 then do following.

  print $1                                ##Printing 1st field of current line here.

  next                                    ##next will skip all further statements from here.

}

{

  num1=split($1,arr1,".")                 ##Splitting $1 into arr1 with delimiter . AND num1 will have total number of elements in arr1.

  num2=split($2,arr2,".")                 ##Splitting $2 into arr2 with delimiter . AND num2 will have total number of elements in arr1.

  for(i=arr1[num1];i<=arr2[num2];i++){    ##Running for loop from last value of 1st field to last value of 2nd field.

     print arr1[1],arr1[2],arr1[3],i      ##Printing arr1 1st, 2nd and 3rd value and then printing value of i here.

  }

}' Input_file                             ##Mentioning Input_file name here.


查看完整回答
反對 回復 2023-12-09
  • 1 回答
  • 0 關注
  • 139 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號