macAddress=$(/sbin/ifconfig eth0 2>nil | grep 'HWaddr' | sed 's/.*HWaddr //' | sed 's/ :*//' | sed 's/:/-/g' | tr A-Z a-z | sed 's/\s//g')
sed -i "s/.../$macAddress" filename
sed -i 's/something/others/' filename means replace somthing to others in filename,replacement will work once,if you add 'g' ,it will replace all matched words in file.
tr A-Z a-z translate capital letter to lowercase
sed 's/\s//g' \s means space, g means globle
' and " are different , ' ' means simple string,do not transfer anything,"" means maybe variable in string,will trransfer first.
本文介绍如何使用Shell脚本获取并替换文件中的MAC地址。通过一系列命令如ifconfig、grep、sed及tr实现从指定网络接口读取MAC地址,并将其转换为所需格式后替换到目标文件中。
1608

被折叠的 条评论
为什么被折叠?



