zoukankan      html  css  js  c++  java
  • shell根据csv生成sql

    member.csv

    Blum,Richard,123 Main St.,Chicago,IL,60601
    Blum,Barbara,123 Main St.,Chicago,IL,60601
    Bresnahan,Christine,456 Oak Ave.,Columbus,OH,43201
    Bresnahan,Timothy,456 Oak Ave.,Columbus,OH,43201

    csv2sql.sh

    #!/bin/bash
    # read file and create INSERT statement for MYSQL
    
    outfile="mem.sql"
    IFS=","
    while read lname fname address city state zip
    do
      cat >> $outfile << EOF
      INSERT INTO members (lname, fname, address, city, state, zip) VALUES
      ('$lname', '$filename', '$address', '$city', '$state', '$zip');
    EOF
    done < ${1}

    执行后生成

    INSERT INTO members (lname, fname, address, city, state, zip) VALUES
      ('Blum', '', '123 Main St.', 'Chicago', 'IL', '60601');
      INSERT INTO members (lname, fname, address, city, state, zip) VALUES
      ('Blum', '', '123 Main St.', 'Chicago', 'IL', '60601');
      INSERT INTO members (lname, fname, address, city, state, zip) VALUES
      ('Bresnahan', '', '456 Oak Ave.', 'Columbus', 'OH', '43201');
      INSERT INTO members (lname, fname, address, city, state, zip) VALUES
      ('Bresnahan', '', '456 Oak Ave.', 'Columbus', 'OH', '43201');
  • 相关阅读:
    第十二周学习进度条
    课堂练习四
    搜狗输入法
    第十一周学习进度条
    《代码大全(第二版)》阅读笔记01
    典型用户及用户场景描述
    第十周学习进度条
    团队冲刺第六天
    团队冲刺第五天
    团队冲刺第四天
  • 原文地址:https://www.cnblogs.com/cangqinglang/p/12444597.html
Copyright © 2011-2022 走看看