批量在数据库的一个列中添加文件中的ip

1)for循环

#!/bin/bash

num=$(wc -l ip.txt | awk '{print $1}')

for ((i=1;i<=$num;i++));

do

ip=$(/bin/sed -n ''"$i"'p' /xiaobai/ip.txt)

mysql -e "use xiaobai;" -e "insert into edm_trace_black_ip_list (value,create_date) values ('$ip',now());"

done

2)while

#!/bin/bash

while read ip

do mysql -e "use xiaobai;" -e "insert into edm_trace_black_ip_list (value,create_date) values ('$ip',now());"

done < /xiaobai/ip.txt

原始文件ip.txt如下

[root@xiaobai xiaobai]# cat ip.txt

1192.168.1.2

1192.168.1.3

1192.168.1.4

1192.168.1.5

1192.168.1.6

1192.168.1.7

1192.168.1.8

1192.168.1.9

1192.168.1.10

1192.168.1.11

1192.168.1.12

1192.168.1.13

1192.168.1.14

1192.168.1.15

1192.168.1.16

1192.168.1.17

1192.168.1.18

1192.168.1.19

1192.168.1.20


你可能感兴趣的:(shell,while,循环,for)