bash 一次处理一行(awk实例)
awk '{printf "host "$3" {\n"" hardware ethernet "$1";\n"" fixed-address "$2";\n""}\n"}' youfile
效果:
host D2 {
hardware ethernet 192.168.0.65;
fixed-address 00:26:18:08:49:8B;
}
host F5 {
hardware ethernet 192.168.0.66;
fixed-address 00:24:8C:66:42:9D;
}
bash 循环读入文件的每一行并处理
cat afile | while read onelinedo
echo $oneline
done
#!/bin/bash
cat aa.txt|while read oneline
do
echo $oneline >oneline
IP=`awk '{printf ""$1"\n"}' oneline`
MAC=`awk '{printf ""$2"\n"}' oneline`
HOSTNAME=`awk '{printf ""$3"\n"}' oneline`
echo $IP
echo $MAC
echo $HOSTNAME
done