我必须从mysql读取一些列并使用bash脚本更改该列,然后在mysql中更新列。 我的Mysql查询就像"从故事中选择描述"。 然后我将遍历结果集的每一行,并使用一些shell脚本编辑描述。编辑后,我将更新该行。 伪代码看起来像:
select id,description from story
for each description in result set
$orig_description=description
$orig_id= id
apply shell script file script.sh ($edited_description=./script.sh)
update story set description=$edited_description where id=$orig_id
完成此任务的最简单方法是什么?以及如何实现它?
答案 0 :(得分:1)
根据您提供的查询和解释,示例脚本将是,
cmd="mysql -u [user] -p[pass]"
cmdRes=$($cmd -e "select id,description from story")
for val in "$cmdRes";
do
#parse val for id and description
#val1=id
#val2=description
#apply modification logic
$cmd -e "update story set desc=${Val2} where id=${val1}"
done