Linux shell script read file line by line All In One
Linux shell 脚本逐行读取文件
I just want to replace thegrep
command, and filter out the real IP address 192.168.18.195
with native
shell syntax
.
#!/usr/bin/env bash
IPs=$(ifconfig | grep -oE '192\.168\.(1?[0-9][0-9]?|2[0-4][0-9]|25[0-5])\.([2-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-4])\b')
echo $IPs
# 192.168.18.195
en1: flags=8863<UP,BROADCAST,SMART,RUNNING,SIMPLEX,MULTICAST> mtu 1500
options=6463<RXCSUM,TXCSUM,TSO4,TSO6,CHANNEL_IO,PARTIAL_CSUM,ZEROINVERT_CSUM>
ether a4:83:e7:91:62:79
inet6 fe80::1ca2:3b0a:df9d:465f%en1 prefixlen 64 secured scopeid 0x7
inet 192.168.18.195 netmask 0xffffff00 broadcast 192.168.18.255
inet6 fd80:eae6:1258:0:37:7544:1d1:7b08 prefixlen 64 autoconf secured
nd6 options=201<PERFORMNUD,DAD>
media: autoselect
status: active
https://gist.github.com/xgqfrms/a9e98b17835ddbffab07dde84bd3caa5
IP
while..do..done
bash loop
# 多个命令写在同一行上,需要使用 `;` 符号分割
while read -r line; do COMMAND; done < input.file
ip-filter.sh
#!/usr/bin/env bash
# 写死文件的绝对路径
标签:shell,script,read,ip,filter,file,line
From: https://www.cnblogs.com/xgqfrms/p/17362135.html