【发布时间】:2016-08-28 21:12:59
【问题描述】:
我正在编写一个脚本来将一列数据复制到另一列。 尝试使用以下逻辑芽没有成功- o/p- 参数个数为0。
我的逻辑- • 我从 admintable 中获取密钥,然后将数据复制到某个 updateupdateStatement 文件中。 • 使用 awk 命令我将特定列数据复制到某个临时文件 • 然后准备一个更新语句,然后执行它。
#!/bin/ksh
#
# Script to Populate cross_refs based on what is in cross_references
#
#
echo "number of parameters is $#"
if [ $# != 1 ]; then
USAGE="USAGE: $0 cassPassword"
echo ${USAGE}
exit 1
fi
cassPassword=$1
#Add column to admin table
#echo "alter table to add column..."
#echo "ALTER TABLE admin.product ADD cross_refs Map<String,String>;" > updateTable.cql
#cqlsh -u dgadmin -p ${cassPassword} -f updateTable.cql
echo "get keys from cassandra"
echo "copy admin.product (cross_references) to 'updateupdateProductStatement.cql';" > copyInputs.cql
cqlsh -u dgadmin -p ${cassPassword} -f copyInputs.cql
#Convert file that Cassandra created from DOS to Unix
echo "DOS to Unix conversion..."
tr -d '\015' <updateupdateProductStatement.cql >updateupdateProductStatement2.cql
cat updateupdateProductStatement2.cql >tempFile
sed -i "s/^/update admin.product set cross_refs = '/" tempFile
#execute the updated .cql file to run all the update statements
echo "executing updateupdateProductStatement.cql..."
cqlsh -u dgadmin -p ${cassPassword} -f tempFile
【问题讨论】:
-
您的标签是 bash,但您的脚本是 ksh。考虑添加一个 ksh 标记并删除 bash 标记,以便您的问题到达目标受众