目的
删除如下注释:
SELECT
-- 注释
name, -- 注释
age, -- 注释
FROM her;
脚本
#!/usr/bin/env bash
INPUT=$1
if [[ "${INPUT}" != "" ]]; then
cat "${INPUT}" | sed 's/--.*//g' | sed '/^[[:space:]]*$/d' > "${INPUT}"
fi
chmod +x del-comment.sh
./del-comment.sh test.sql
参考
- http://www.cocoachina.com/cms/wap.php?action=article&id=50179
- http://main.net.cn/os/linux/how-do-i-get-sed-to-read-from-standard-input/