sh name.sh yuming.txt yuming_bak.txt
for name in `cat $1`
do
echo "www.$name||:80:www.$name,:80:$name||d:\wwwroot\www.$name" >> $2
done
[root@nagios_client1 domain]# cat modify.sh
#!/usr/bin/bash
file_number=`ls /root/domain/*.txt|wc -l`
#echo $file_number
for i in `ls /root/domain/*.txt`
do
[ ${i##*-} == "1.txt" ] && sh /root/domain/name.sh ${i} ${i}_bak || sh /root/domain/name2.sh ${i} ${i}_bak
done
注:[ ${i##*-} == "1.txt" ] #以判断文件名执行相关脚本
格式化域名和IP解析格式
cat jiexi.sh
#!/usr/bin/bash
path="/root/domain/"
read -p "please input file name number:" file_number
read -p "please input ip before 3 number like:192.168.1:" ip_number
#echo $file_number
#echo $ip_number
cat /root/domain/${file_number}-1.txt > /root/domain/${file_number}_yuming
echo "" >> ${path}${file_number}_yuming
cat /root/domain/${file_number}-2.txt >> /root/domain/${file_number}_yuming
seq -f "${ip_number}.%01g" 3 252 > ${path}${file_number}_ip
#echo "" >> ${path}${file_number}_ip
seq -f "${ip_number}.%01g" 3 252 >> ${path}${file_number}_ip
n=1
ip_line=`cat ${path}${file_number}_ip|wc -l`
while [ ${n} -le ${ip_line} ]
do
ym=`sed -n "${n},${n}p" ${path}${file_number}_yuming` && ip=`sed -n "${n},${n}p" ${path}${file_number}_ip`
echo "${ym},${ip}" >> ${path}${file_number}_format
let n+=1
done
可以简单点,去掉while循环代码,使用:
paste -d,${path}${file_number}_yuming ${path}${file_number}_ip >> ${path}${file_number}_format