How to read from multiple files

Hi All,

I have list of multiple files with 7 fields all together. Those are being split to exact lines of 20000 each.

xaa
xab
:
:
:
xhx

Please advise me how to read from those files and in fact I need to invoke and sql update statement for each inputs values..

Regards,

Cedrichiu,
Please specify more details and give us an example of your input and
expected output.

Hi Shell_Life,

If I list out content of

> cat xaa | head

392183921|94389549|A584958|TOM|11, CON STREET|BROADWAY|1122

Somehow, this is what could figure out on how to read from if it is single file

while read file
do
_msisdn=$(echo $file | cut -d "|" -f 1)
_cust_ic=$(echo $file | cut -d "|" -f 2)
_cust_pass=$(echo $file | cut -d "|" -f 3)
_cust_name=$(echo $file | cut -d "|" -f 4)
_cust_street1=$(echo $file | cut -d "|" -f 5)
_cust_street2=$(echo $file | cut -d "|" -f 6)
_cust_post=$(echo $file | cut -d "|" -f 7)
echo "UPDATE customer SET cust_alt_fax='$_cust_ic',cust_bld_nr='$_cust_pass',cust_name='$_cust_name',cust_street_1='$_cust_street1',cust_street
_2='$_cust_street2',cust_add_pcode='$_cust_post',chk_upd_dt=CURRENT" >> upd_addl_reg.sql
echo "WHERE cust_msisdn='$_msisdn';" >> upd_addl_reg.sql
done < xaa , xab... ... xhx

Due to db limitation, I have to perform update 20000 rows at a time to reduce load, that's why you could see i split files to several as named below. :slight_smile:

Please advise

Cedrichiu,
See if this works for you:

for mFile in x?
do
  echo "Now working with file "$mFile" at "`date`
  mOutFile=$mFile".sql"
  while read mLine
  do
    _msisdn=$(echo $mLine | cut -d "|" -f 1)
    .......
    echo "WHERE cust_msisdn='$_msisdn';" >> $mOutFile
  done < $mFile
done

You will have an sql file for each split file.

hi,

I'm not sure whether if conditional statement correct or not? Please advise
Basically, if the field 2 exist and with value , it will be update set as cust_alt_fax column and if field 3 exist and with value, update set as cust_alt_fax , else field 4 exist and with value, update set as cust_alt_fax column

Cedrichiu,
To test if a variable has a value:

if [ -n "${YourVar}" ]; then
  echo "Variable "${YourVar}" is not empty"
else
  echo "Variable "${YourVar}" is empty"
fi