1

I have a file with data :

bq --schema
corp:STRING,                                               
region:STRING,                                                                                      
load_date_time:TIMESTAMP)                                      
bq --schema
corp:STRING,                                                                                          
load_date_time:TIMESTAMP) 

and a String variable as :

table1

table2

What i want to do is to replace ')' to an array element and the final output should look like :

bq --schema
corp:STRING,                                               
region:STRING,                                                                                      
load_date_time:TIMESTAMP table1                                  
bq --schema
corp:STRING,                                                                                          
load_date_time:TIMESTAMP table2

The string variable is generated from below file :

CREATE TABLE UK_CHAIN_PARM_ADDL_FUNDING(                                      
corp:STRING,                                                            
region:STRING,                                                          
prin:STRING,                                                            
assc:STRING,                                                            
chain:STRING,                                                           
acct_ind:STRING,                                                        
transit_nbr:INTEGER,                                                            
dda_nbr:STRING,                                                        
currency:STRING,                                                        
mask:STRING,                                                            
value_dt:INTEGER                                                              
)                                                                                                   
CREATE TABLE UK_SUPPLEMENTAL_FUNDING(                                      
merchant:STRING,                                                    
acct_ind:STRING,                                                     
transit_nbr:INTEGER,                                                         
dda_nbr:STRING,                                                     
currency:INTEGER,                                                            
mask:STRING,                                                         
value_dt:INTEGER,                                                            
beneficiary:STRING,                                                 
vbc_line_1:STRING                                                  
)                                                

CREATE TABLE UK_REGION_PARM(                                      
corp:STRING,                                                
region:STRING,                                              
end_point:STRING,                                           
currency_code:STRING,                                       
tax_id1:STRING,                                             
tax_id2:STRING,                                             
load_date_time:TIMESTAMP)                                       

for extracting just table names i have used below command Tablenames=$(grep -i 'create table' $myfilename | awk -F ' ' 'BEGIN{ORS="\n";}{print $3}' | tr "(" "\n")

So ultimately i want output in format

bq --schema "schema of the table" -t tablename

0

1 Answer 1

1

Finally i found the answer. So instead of using the array i placed string values inside a file with new line separation.

The code i have written to achieve expected output :

while read line1
do
found=$(echo $line1 | grep -c ")")
if [ $found != 0 ];
then
while read line2
      do
           alreadycontainTable=$(grep -c "$line2" NewFileWithTableName.txt)
        if [ $alreadycontainTable == 0 ];
           then
           tableName=$(echo $line2)                       
           echo $line1 | sed -r "s/\)/ -t $tableName/" >> NewFileWithTableName.txt
          break;
        fi
            done < table.txt
else
           echo $line1 >> NewFileWithTableName.txt
fi
done < fileWithBrackets.txt
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.