linux遍歷文件以及文件夾入數據庫

#!/bin/bash
for dir in $(ls -l |grep ^d)
do
        if [ -d  $dir ]; then
                cd $dir
                for file in `ls ./`
                do


                        #統計行數
                        count=$(cat $file | wc -l)
                        for ((i=1;i<=$count;i++))
                        do
                                j=$(expr $i + 1)
                                k=$i,$j'p'
                                one=$(sed -n $k $file)
                                date=$(echo $one | awk '{print $1}' )
                                tim=$(echo $one | awk '{print $2}' )
                                create_time=$date' '$tim
                                if [[ $i == 1 ]];then
                                    echo $date 
                                fi
                                echo $i/$count
                                session_id=$(echo $one | awk '{print $4}')
                                content=$(echo $one | awk '{print $5}')


                                mysql -hlocalhost -uroot -pvfc123456  <<EOF
                                use test
                                INSERT INTO test.log (id, session_id, content, create_time, is_trans) VALUES (NULL, '$session_id', '$content', '$create_time', '0');
EOF
                        done


                done
                cd ..
        echo 'finished'
        fi
done
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章