I have the following working function in my bash script:
addMD5SUM()
{
file=$COLS2
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"
}
Where $COL2 is a single filename:
COLS2="myoutputfile2.out"
Contents of this file would be something like:
visitor_id
updated
visitor_list_1
visitor_list_2
visitor_list_3
visitor_list_4
visitor_list_5
Other files would be similar: (i.e.)
visitor_id
updated
visitor_list_6
visitor_list_7
visitor_list_8
visitor_list_9
visitor_list_10
Now, I need to alter this function so that I have the option to have it work with either one of these files:
export COLS1="myoutputfile1.out"
export COLS2="myoutputfile2.out"
export COLS3="myoutputfile3.out"
export COLS4="myoutputfile4.out"
How would you do this? Would you do this as an if-statement? What is the best and proper way to do handle this?
linecount=$(wc -l <"$file")