用于将一个列数据复制到另一个列的脚本

时间:2016-05-03 17:30:45

标签: sql shell ksh cql cqlsh

我正在编写一个脚本来将一个列数据复制到另一个列。 尝试以下逻辑芽没有解决 - 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

1 个答案:

答案 0 :(得分:0)

我并不完全确定我理解你的剧本的意图,但我可以选出一行看起来很可疑......

cat updateFlatFileInputStatements2.cql |awk -F'\t' '{ 19                1              2}'  >tempFile

我认为您要将第19,1和2列打印到输出中......

awk -F'\t' 'BEGIN { OFS="         " }{ print $19, $1, $2 }' updateFlatFileInputStatements2.cql > tempFile

最好是在 awk

中对tempFile进行所有操作
awk -F'\t' "{ print \"update admin.product set my_refs = \" \$19 \" where id = \" $1 \" and effective_date = \" $2 \"';\"" updateFlatFileInputStatements2.cql > tempFile

然后,我再次在您的文件中看不到使用tempFile的地方......或者生成updateFlatFileInputStatements2.cql的地方。看起来这段代码什么都不做?

updateupdateStatement.cql ...不知道它来自哪里。然后将其删除以形成updateupdateStatement2.cql ...然后被操纵变为tempFile但是......您不使用tempFile - 而是将updateupdateStatement2.cql发送到cqlsh。该错误可能是您打算将tempFile发送给最终的cqlsh

相关问题