0

Please check and correct me. While passing the * in the the variable , it is select all the files in the folder.

    <<<
    cat /home/spanda20/p2020/m23/query/p2020_m23_ora_sqoop_unld_query.dat
loc_query|”select * from SCPOMGR.LOC where \$CONDITIONS”
    export SQOOP_QUERY_FILE='/home/spanda20/p2020/m23/query/p2020_m23_ora_sqoop_unld_query.dat'
    export TBL_NM='loc'
    TBL_QUERY=`grep ${TBL_NM}_query ${SQOOP_QUERY_FILE} | awk -F "|" '{print $2}'`
    sqoop import --connect xxxx --username yyyy --password zzzzz --query "$TBL_QUERY" >>>

Output I am getting:

    ++ grep loc_query /home/spanda20/p2020/m23/query/p2020_m23_ora_sqoop_unld_query.dat
    ++ awk -F '|' '{print $2}'
    + export 'TBL_QUERY="select * from SCPOMGR.LOC where \$CONDITIONS"'
    + TBL_QUERY='"select * from SCPOMGR.LOC where \$CONDITIONS"'
    + echo TBL_QUERY : '"select * from SCPOMGR.LOC where \$CONDITIONS"'
    TBL_QUERY : "select * from SCPOMGR.LOC where \$CONDITIONS"
sqoop import --connect jdbc:oracle --username MA7D --password W_123 --query '"select * from SCPOMGR.LOC where \$CONDITIONS"' --target-dir /user/spanda20/informatica_p2020/p2020/stg/m23/20150401 -m 1

If you see , the select statement is started with single quote and a double and also ending with same. I need only a double quote.

ex:
TBL_QUERY : "select * from SCPOMGR.LOC where \$CONDITIONS"
user3858193
  • 1,320
  • 5
  • 18
  • 50
  • 2
    please take a few minutes to fix the formatting of your question. It is extremely hard to read. When inserting literal code, either indent each line by four spaces, or surround the data with backticks (eg: \`\`) – Bryan Oakley Jul 08 '15 at 14:12
  • 1
    1) What shell are you using? I suppose we can *assume* Bash, but maybe not? 2) Your shell is clearly interpreting within double quotes. Try single quotes. – James Sumners Jul 08 '15 at 14:18
  • The code formatting toolbar item (`{}`) is also useful for this. – Etan Reisner Jul 08 '15 at 14:18
  • 3
    Double quote the variable expansion. `echo "$TBL_QUERY"` In general **always** quote variable expansions. – Etan Reisner Jul 08 '15 at 14:20
  • See [this question](http://stackoverflow.com/q/29378566/258523) for more on the topic of quoting variables. – Etan Reisner Jul 08 '15 at 14:22
  • I am using bash shell. Double quote is working.I did modify my script echo "sqoop import job" TBL_QUERY=`grep ${TBL_NM}_query ${SQOOP_QUERY_FILE} | awk -F "|" '{print $2}'` echo sqoop import --connect $JDBC_CON --username $USERNAME --password $PASSWORD --query "${TBL_QUERY}" --target-dir $HDFS_PATH -m 1 Output:TBL_QUERY=' "select * from SCPOMGR.LOC where \$CONDITIONS" ' .I need a out of "select * from SCPOMGR.LOC where \$CONDITIONS" only. – user3858193 Jul 08 '15 at 14:48
  • 1
    [This Unix&Linux question](https://unix.stackexchange.com/questions/171346/security-implications-of-forgetting-to-quote-a-variable-in-bash-posix-shells) is also important. – glenn jackman Jul 08 '15 at 14:48
  • @EtanReisner ..Stiill finding issue.. Can you pls help me out . export SQOOP_QUERY_FILE='/home/spanda20/p2020/m23/query/p2020_m23_ora_sqoop_unld_query.dat' export TBL_NM='loc' TBL_QUERY=`grep ${TBL_NM}_query ${SQOOP_QUERY_FILE} | awk -F "|" '{print $2}'` I need below output "select * from SCPOMGR.LOC where \$CONDITIONS" but I am getting '"select * from SCPOMGR.LOC where \$CONDITIONS"' ... – user3858193 Jul 08 '15 at 20:33
  • Comments really aren't for code. I don't see any difference between what you say you get and what you say you want in that comment. If simply quoting your variables wasn't enough then please update your question with your current set of commands and with the **exact** output you are getting and the **exact** output you would like to be getting so we can help you. – Etan Reisner Jul 09 '15 at 01:59

0 Answers0