I need help figuring out why my case statement is not properly evaluating my first 2 values (visitor_id, updated) in my list.
Here's the code:
#!/usr/local/bin/bash
file="mydatasample.out";
linecount=$(wc -l <"$file" | awk '{ print $1 }')
counter=1
while IFS='' read -r column; do
case column in
visitor_id)
echo "isnull($column|| '[|]' ||";;
updated)
echo "isnull($column::text || '[|]' ||";;
*)
echo "isnull($column::text,'[null!]') || '[|]' ||";;
esac
if [ "$counter" -eq "$linecount" ]; then
echo "isnull($column::text,'[null!]')) as md5sum"
fi
((counter++))
done <"$file"
=mydatasample.out=
visitor_id
updated
visitor_1_key
visitor_1_value
visitor_2_key
visitor_2_value
Getting:
isnull(visitor_id::text,'[null!]') || '[|]' ||
isnull(updated::text,'[null!]') || '[|]' ||
isnull(visitor_1_key::text,'[null!]') || '[|]' ||
isnull(visitor_1_value::text,'[null!]') || '[|]' ||
isnull(visitor_2_key::text,'[null!]') || '[|]' ||
isnull(visitor_2_value::text,'[null!]')) as md5sum
Expecting:
isnull(visitor_id|| '[|]' ||
isnull(updated::::text || '[|]' ||
isnull(visitor_1_key::text,'[null!]') || '[|]' ||
isnull(visitor_1_value::text,'[null!]') || '[|]' ||
isnull(visitor_2_key::text,'[null!]') || '[|]' ||
isnull(visitor_2_value::text,'[null!]')) as md5sum
So, its the first (2) values that I want to evaluate, but so far cannot. Thanks for your help.
case "$column" in ...?linecountandcounterstuff, just put theecho "... as md5sum"command after the loop, so it runs with the last value of$column.readsetscolumnto each line as it's read, but after the last line there's a finalreadthat reads the end-of-file and setscolumnto null. But if you addlastcolumn=$columninside the loop, then after the loop that'll have the last actual column left in thecolumnvariable, and you can use that to print the "... as md5sum".