i have a requirement to run a Linux for loop for a list of tables and their respective queries.
The file which has loop entries look like (sample entry)-
user@server-edge:/tmp $ cat linuxForLoop.txt
MY_TABLE|SCD1|Select * from db.MY_TABLE where EFFECTIVE_DATE='X'
When i am reading this file in a for loop and trying to pass parse values to another script, it is behaving abnormal while evaluating the query from the file.
user@server-edge:/tmp $ for i in `cat linuxForLoop.txt`
> do
> tableName=`echo $i | cut -d "|" -f1`
> echo $tableName
> tableType=`echo $i | cut -d "|" -f2`
> echo $tableType
> query=`echo $i | cut -d "|" -f3`
> echo $query
> done
MY_TABLE
SCD1
Select
00020a9b-da3a-418e-9b7d-10971e901354_resources
00020a9b-da3a-418e-9b7d-10971e901354_resources
00020a9b-da3a-418e-9b7d-10971e901354_resources
it echos the table name and type without an issue when it reaches to parse the query to variable "query", it is actually listing everything from the directory. Why is it behaving like this when i am forcing it to read the file by "PIPE" delimiter ?
Desired outcome-
user@server-edge:/tmp $ for i in `cat linuxForLoop.txt`
> do
> tableName=`echo $i | cut -d "|" -f1`
> echo $tableName
> tableType=`echo $i | cut -d "|" -f2`
> echo $tableType
> query=`echo $i | cut -d "|" -f3`
> echo $query
> done
MY_TABLE
SCD1
Select * from db.MY_TABLE where EFFECTIVE_DATE='X'