there is my script:
table_nm=$1
hive_db=$(echo $table_nm | cut -d'.' -f1)
hive_tb=$(echo $table_nm | cut -d'.' -f2)
At first, I got the right result:
$echo "dev.dmf_bird_cost_detail" | cut -d'.' -f1
dev #correct
$echo "dev.dmf_bird_cost_detail" | cut -d'.' -f2
dmf_bird_cost_detail #correct
but,i got something is wrong,if there is no specified character in $table_nm, I get this result:
$echo "dmf_bird_cost_detail" | cut -d'.' -f1
dmf_bird_cost_detail
$echo "dmf_bird_cost_detail" | cut -d'.' -f2
dmf_bird_cost_detail
$echo "dmf_bird_cost_detail" | cut -d'.' -f3
dmf_bird_cost_detail
The result that is not I expected, i hope it's empty, so i conducted some tests and found that if there is no specified character in the string, the command "cut" will return the original value, is that true?
At last,i know "awk" will solves my problem, but I would like to know why "cut" has the above result? Thank you guys so much!