皮总,请教问题。。。

啊啊哦哦哦 发布于 2013/08/02 16:57
阅读 310
收藏 0

@皮总 你好,想跟你请教个问题:

#!/bin/bash

site_count=5

for i in `cat domain.txt`
do
        for (( j=1;j<=$site_count;j++))
        do
        matrix="0123456789abcdefghijklmnopqrstuvwxyz"
        length="8"
        while [ "${num:=1}" -le "$length" ];do
        code="$code${matrix:$(($RANDOM%${#matrix})):1}"
        let num+=1
        done
        #echo $code.$i  >> domain111.txt
	echo "(${j}, ${j}, '${code}.${i}', 1);" >> domain111.txt
	unset num
        unset code
done
done

输出的结果是这样的。

(1, 1, '9isjdske.123.com', 1);
(2, 2, 'ecn7xwwv.123.com', 1);
(3, 3, '6pn4lm1n.123.com', 1);
(4, 4, 'w5je9fui.123.com', 1);
(5, 5, 'yntbfehm.123.com', 1);
(1, 1, 'jxu8mi4t.44123.com', 1);
(2, 2, '8rxleq12.44123.com', 1);
(3, 3, 'vch5sbfi.44123.com', 1);
(4, 4, 'q9uyf3ly.44123.com', 1);
(5, 5, '1gzny38z.44123.com', 1);
(1, 1, 'nyctp5wl.21312321312.com', 1);
(2, 2, 'a5i29qlz.21312321312.com', 1);
(3, 3, 'z7yebj55.21312321312.com', 1);
(4, 4, 'rwti029f.21312321312.com', 1);
(5, 5, '0e9qj53u.21312321312.com', 1);

想要输出的结果是这样的,我代码该怎么改呢?

(1, 1, '9isjdske.123.com', 1);
(2, 2, 'ecn7xwwv.123.com', 1);
(3, 3, '6pn4lm1n.123.com', 1);
(4, 4, 'w5je9fui.123.com', 1);
(5, 5, 'yntbfehm.123.com', 1);
(6, 6, 'jxu8mi4t.44123.com', 1);
(7, 7, '8rxleq12.44123.com', 1);
(8, 8, 'vch5sbfi.44123.com', 1);
(9, 9, 'q9uyf3ly.44123.com', 1);
(10, 10, '1gzny38z.44123.com', 1);
(11, 11, 'nyctp5wl.21312321312.com', 1);
(12, 12, 'a5i29qlz.21312321312.com', 1);
(13, 13, 'z7yebj55.21312321312.com', 1);
(14, 14, 'rwti029f.21312321312.com', 1);
(15, 15, '0e9qj53u.21312321312.com', 1);

加载中
0
皮总
皮总
#!/bin/bash

site_count=15
k=1

for i in `cat domain.txt`; do
       for ((j=1;j<=$site_count;j++)); do
                matrix="0123456789abcdefghijklmnopqrstuvwxyz"
                length="8"
                while [ "${num:=1}" -le "$length" ];do
                        code="$code${matrix:$(($RANDOM%${#matrix})):1}"
                        let num+=1
                done
                echo "($k, $k, '${code}.${i}', 1);"
                let k++
                unset num
                unset code
        done
done
皮总
皮总
引入一个 k 来存储这个序号就行了
0
皮总
皮总
我看看先, 稍等!
0
啊啊哦哦哦
啊啊哦哦哦

引用来自“皮总”的答案

我看看先, 稍等!
谢谢皮总。
0
啊啊哦哦哦
啊啊哦哦哦

引用来自“皮总”的答案

#!/bin/bash

site_count=15
k=1

for i in `cat domain.txt`; do
       for ((j=1;j<=$site_count;j++)); do
                matrix="0123456789abcdefghijklmnopqrstuvwxyz"
                length="8"
                while [ "${num:=1}" -le "$length" ];do
                        code="$code${matrix:$(($RANDOM%${#matrix})):1}"
                        let num+=1
                done
                echo "($k, $k, '${code}.${i}', 1);"
                let k++
                unset num
                unset code
        done
done
,爱死你,谢谢!!!
返回顶部
顶部