Created
September 17, 2025 00:01
-
-
Save freelze/444fa203faddfd4474ae8af3a5d23e0d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| awk ' | |
| # 處理第一個檔案 (dhcp_lease_list.txt) | |
| FNR==NR { | |
| # 只處理包含 ":" 的行 (過濾掉表頭和 "Processing" 行) | |
| if ($1 ~ /:/) { | |
| # 建立一個陣列,以 MAC (第一個欄位) 為索引,IP (第二個欄位) 為值 | |
| leases[$1] = $2 | |
| } | |
| # 繼續讀取下一行,不要執行下面的程式碼區塊 | |
| next | |
| } | |
| # 處理第二個檔案 (MAC_TABLE.txt) | |
| { | |
| # 檢查這個 MAC 是否存在於我們建立的陣列中 | |
| if ($1 in leases) { | |
| # NR - FNR 會得到第二個檔案的行號,也可以用 count++ | |
| # 使用 printf 格式化輸出,%02d 代表補零到兩位數的數字 | |
| printf "%02d,%s\n", (NR - FNR), leases[$1] | |
| } | |
| } | |
| ' dhcp_lease_list.txt MAC_TABLE.txt > IP_table.txt |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment