我想通过awk shell直接在mysql中插入数据

时间:2013-12-22 12:15:59

标签: shell awk

如何在mysql中直接插入数据.. 听到的是代码


    awk '
    BEGIN {
    FS=";";
    }
    {
     if(NR>1)
     {
      Max =  $1
      Min  = $2
     Com  = $3
      if(Max>Com)
       {
        NMax = Max
        if(Max>Com && NMaxMin)
      {   
        NMin = Min
        if(Min1)                
      printf "%9.2f;%9.2f;%9.2f;%9.2f;%9.2f;\n", $1,$2,$3,NMax,NMin
    }' data.txt 

#mysql -uroot -proot wcdata和table name-data_com

提前致谢....

1 个答案:

答案 0 :(得分:2)

以下是一个建议:您可以尝试使用printf语句代替:

istr="INSERT INTO data_com"
cstr="(Column001, Column002, Column003, Column004, Column005)"
cmd="echo "istr" "cstr" VALUES ("
cmd=sprintf("%s'%.2f','%.2f','%.2f','%.2f','%.2f'\)", cmd,a1[i],a2[i],a3[i],a,b)
cmd= cmd " | mysql -uroot -proot wcdata"
system(cmd)