sed拆分一行为多行

sed拆分一行为多行

#!/bin/bash
# Author: royoy

sql=/data/shell/ubuntu/pay_db/sql
ip=x.x.x.x
plat_env="$1"
shift

#if `echo "$@" | sed '/^$/d' |sed -E 's/[; ]+(select|update|delete)/\n\1/gi' |sed '/^$/d' > $sql`;then

if `echo "$@" | sed ':m;N;s/\n//g;$!bm' |sed -E 's/;/;\n/g' |sed '/^$/d;s/\s\+/ /g;s/^\s\+//' > $sql`;then
    if `scp $sql $ip:/home/ubuntu/pay_db/sql`;then
        ssh -o ConnectTimeout=9 $ip "/bin/bash /home/ubuntu/pay_db/pay_db.sh '$plat_env'"
    else
        echo "scp sql failed"
        exit 21
    fi 
else
    echo "write into sql file failed"
    exit 13
fi