Results 1 to 5 of 5
  1. #1
    Join Date
    Jul 2011
    Posts
    4

    Unanswered: Read line of files and call store procedures [Urgent]

    Hi,

    I wish to write a piece of code to read lines of the flat file and cut each lines of record to a variable, then use this variable to pass as an parameter of a Sybase stored procedures, if there are 5 lines of record from the text file, then this stored procedures will be called 5 times.
    But I keep on hit the error:
    syntax error at line 56 : `<' unmatched

    Here are my code:
    #!/bin/ksh
    . /production/kltools/profiles/profile.cron
    ClientDir=/home/abc/
    ClientSrcDir=$ClientDir/test
    ClientLogDir=$ClientDir/log
    ClientTgtDir=$ClientDir/data
    ClientScriptDir=$ClientDir/script
    Log=$ClientLogDir/load.log
    InFile=$ClientTgtDir/test.txt
    Log_Temp=$ClientLogDir/load_data.log
    rm -f $Log $OutFile
    if [[ -f $Log ]]
    then
    echo "Error: Could not remove log file $Log"
    exit 1
    fi

    if [[ -f $OutFile ]]
    then
    echo "Error: Could not remove $OutFile" >> $Log
    exit 1
    fi

    # replace
    i=0

    for line in $InFile
    do
    COM_NUM=`cut -c138-140 $line`
    PLAN=`cut -c141-142 $line`
    EMPID=`cut -c65-73 $line`
    AMT1=`cut -c148-157 $line`
    AMT2=`cut -c158-162 $line`
    Comp_code="ABC"
    Server="TEST"
    Database="SERVER1"
    if [[ -f $Log_Temp ]]
    then
    echo "Error: Could not remove file $Log_Temp"
    exit 1
    fi
    ksql -S $Server <<-EOF >> $Log_Temp
    use $Database
    go
    exec PROD1 '$COM_NUM', '$PLAN', 'EMPID', $AMT1, $AMT2
    go
    EOF
    ReturnStatus=$?
    if [[ $ReturnStatus != "0" ]]
    then
    echo "Error: ksql failure in inserting." >> $Log
    exit 1
    fi

    done

    line 56 should be as following:
    ksql -S $Server <<-EOF >> $Log_Temp

    but I tried to remove the syntax for..loop, then this error not show, however, I need variable to store data from each line (from the test.txt) and pass to procedures.

    Thanks in advance.
    Last edited by newbie2011; 08-31-13 at 10:16.

  2. #2
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Code:
    ksql -S $Server <<-EOF >> $Log_Temp
    You should remove the minus sign before EOF.

  3. #3
    Join Date
    Jul 2011
    Posts
    4
    I try this before, it doesn't solve the problem.

  4. #4
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Can you re-post your code using code tags and line numbers.
    When you use <<EOF the end of EOF marker has to start in column 1.

  5. #5
    Join Date
    Sep 2009
    Location
    Ontario
    Posts
    1,057
    Provided Answers: 1
    Change the for loop to:
    Code:
    while read line
    do
    ...
    done <$InFile
    change the cut statements to:
    PLAN=`echo $line|cut -c141-142`

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •