LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 06-04-2014, 03:23 AM   #1
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Rep: Reputation: Disabled
code is giving error


Hi,

i have a data file as:

cat INPUT_DATA
03-06-2014|01:45:00|Successful Transactions|1002
03-06-2014|01:45:00|Successful Transactions Amount|273.54
03-06-2014|01:45:00|FAS Failure Transactions|98723
03-06-2014|01:45:00|FAS Failure Transactions Amount|86.82
03-06-2014|01:45:00|Falcon Failure Transactions|14
03-06-2014|01:45:00|Falcon Failure Transactions Amount|51.350

Code:
file="INPUT_DATA"

while IFS=\| read DATE TIME LABEL VALUE  # IFS = Internal File Seperator
do
        if [[ $LABEL == "Successful Transactions" ]]
        then
        succ_trnx=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ $LABEL == "Successful Transactions Amount" ]]
        then
        succ_trnx_amt=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ $LABEL == "FAS Failure Transactions" ]]
        then
        fas_fail_trnx=$(echo "${VALUE}" |sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ $LABEL == "FAS Failure Transactions Amount" ]]
        then
        fas_fail_trnx_amt=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ $LABEL == "Falcon Failure Transactions" ]]
        then
        flcon_fail_trnx=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ $LABEL == "Falcon Failure Transactions Amount" ]]
        then
        flcon_fail_trnx_amt=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi
     

        hour=$(echo ${TIME} | cut -c1-5)
        date1=$DATE
       
        TOT_TRNXS=$(echo "$succ_trnx + $fas_fail_trnx + $flcon_fail_trnx"| bc)
        TOT_FAS_DCLD_TRNXS=${fas_fail_trnx}
        TOT_FLCN_DCLD_TRNXS=${flcon_fail_trnx}
        TOT_TRNX_AMT=$(echo "scale=2; succ_trnx_amt+fas_fail_trnx_amt+flcon_fail_trnx_amt"|bc)
        TOT_DCLD_TRNXS_AMT=$(echo "scale=2; ${fas_fail_trnx_amt}+${flcon_fail_trnx_amt}"|bc)

        echo "TOT_TRNXS=$TOT_TRNXS"
        echo "TOT_FAS_DCLD_TRNXS=$TOT_FAS_DCLD_TRNXS"
        echo "TOT_FLCN_DCLD_TRNXS=$TOT_FLCN_DCLD_TRNXS"
        echo "TOT_TRNX_AMT=$TOT_TRNX_AMT"
        echo "TOT_DCLD_TRNXS_AMT=$TOT_DCLD_TRNXS_AMT"


done <"$file"
error:
(standard_in) 1: parse error
(standard_in) 1: parse error
TOT_TRNXS=
TOT_FAS_DCLD_TRNXS=
TOT_FLCN_DCLD_TRNXS=
TOT_TRNX_AMT=0
TOT_DCLD_TRNXS_AMT=
(standard_in) 1: parse error
(standard_in) 1: parse error
TOT_TRNXS=
TOT_FAS_DCLD_TRNXS=
TOT_FLCN_DCLD_TRNXS=
TOT_TRNX_AMT=0
TOT_DCLD_TRNXS_AMT=
(standard_in) 2: parse error
(standard_in) 1: parse error
TOT_TRNXS=
TOT_FAS_DCLD_TRNXS=98723
TOT_FLCN_DCLD_TRNXS=
TOT_TRNX_AMT=0
TOT_DCLD_TRNXS_AMT=
(standard_in) 2: parse error
(standard_in) 2: parse error
TOT_TRNXS=
TOT_FAS_DCLD_TRNXS=98723
TOT_FLCN_DCLD_TRNXS=
TOT_TRNX_AMT=0
TOT_DCLD_TRNXS_AMT=
(standard_in) 2: parse error
TOT_TRNXS=99739
TOT_FAS_DCLD_TRNXS=98723
TOT_FLCN_DCLD_TRNXS=14
TOT_TRNX_AMT=0
TOT_DCLD_TRNXS_AMT=
TOT_TRNXS=99739
TOT_FAS_DCLD_TRNXS=98723
TOT_FLCN_DCLD_TRNXS=14
TOT_TRNX_AMT=0
TOT_DCLD_TRNXS_AMT=138.170



could someone please help to sort out this error?

Last edited by santosh0782; 06-04-2014 at 03:27 AM.
 
Old 06-04-2014, 03:38 AM   #2
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,767

Rep: Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886
yes, insert set -xv at the beginning of the script and you will see what's happening.
put your variable inside ", so use "$LABEL", also check other variables. in line TOT_TRNX_AMT= even the $ signs are missing....
 
Old 06-04-2014, 04:55 AM   #3
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
yes, insert set -xv at the beginning of the script and you will see what's happening.
put your variable inside ", so use "$LABEL", also check other variables. in line TOT_TRNX_AMT= even the $ signs are missing....
i have added the " to "$LABEL" and $ sign to the missings one, also run the script in debugging mode:
Code:
#!/bin/ksh
set -xv

file="INPUT_DATA"

while IFS=\| read DATE TIME LABEL VALUE  # IFS = Internal File Seperator
do
        if [[ "$LABEL" == "Successful Transactions" ]]
        then
        succ_trnx=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ "$LABEL" == "Successful Transactions Amount" ]]
        then
        succ_trnx_amt=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ "$LABEL" == "FAS Failure Transactions" ]]
        then
        fas_fail_trnx=$(echo "${VALUE}" |sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ "$LABEL" == "FAS Failure Transactions Amount" ]]
        then
        fas_fail_trnx_amt=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ "$LABEL" == "Falcon Failure Transactions" ]]
        then
        flcon_fail_trnx=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi

        if [[ "$LABEL" == "Falcon Failure Transactions Amount" ]]
        then
        flcon_fail_trnx_amt=$(echo "${VALUE}" | sed -e 's/^ *//g;s/ *$//g')
        fi


        hour=$(echo ${TIME} | cut -c1-5)
        date1=$DATE

        TOT_TRNXS=$(echo "$succ_trnx + $fas_fail_trnx + $flcon_fail_trnx"| bc)
        TOT_FAS_DCLD_TRNXS=${fas_fail_trnx}
        TOT_FLCN_DCLD_TRNXS=${flcon_fail_trnx}
        TOT_TRNX_AMT=$(echo "scale=2; $succ_trnx_amt + $fas_fail_trnx_amt + $flcon_fail_trnx_amt"|bc)
        TOT_DCLD_TRNXS_AMT=$(echo "scale=2; ${fas_fail_trnx_amt}+${flcon_fail_trnx_amt}"|bc)


        echo "TOT_TRNXS=$TOT_TRNXS"
        echo "TOT_FAS_DCLD_TRNXS=$TOT_FAS_DCLD_TRNXS"
        echo "TOT_FLCN_DCLD_TRNXS=$TOT_FLCN_DCLD_TRNXS"
        echo "TOT_TRNX_AMT=$TOT_TRNX_AMT"
        echo "TOT_DCLD_TRNXS_AMT=$TOT_DCLD_TRNXS_AMT"
done <"$file"
part of output:
+ 0< INPUT_DATA
+ read DATE TIME LABEL VALUE
+ IFS='|'
+ [[ 'Successful Transactions' == 'Successful Transactions' ]]
+ echo 1002
+ sed -e 's/^ *//g;s/ *$//g'
+ succ_trnx=1002
+ [[ 'Successful Transactions' == 'Successful Transactions Amount' ]]
+ [[ 'Successful Transactions' == 'FAS Failure Transactions' ]]
+ [[ 'Successful Transactions' == 'FAS Failure Transactions Amount' ]]
+ [[ 'Successful Transactions' == 'Falcon Failure Transactions' ]]
+ [[ 'Successful Transactions' == 'Falcon Failure Transactions Amount' ]]
+ echo 01:45:00
+ cut -c1-5
+ hour=01:45
+ date1=03-06-2014
+ echo '1002 + + '
+ bc
(standard_in) 1: parse error
+ TOT_TRNXS=''
+ TOT_FAS_DCLD_TRNXS=''
+ TOT_FLCN_DCLD_TRNXS=''
+ echo scale='2; + + '
+ bc
(standard_in) 1: parse error
+ TOT_TRNX_AMT=''
+ echo scale='2; +'
+ bc
(standard_in) 1: parse error
+ TOT_DCLD_TRNXS_AMT=''
+ echo TOT_TRNXS=
TOT_TRNXS=
+ echo TOT_FAS_DCLD_TRNXS=
TOT_FAS_DCLD_TRNXS=


not able to understand, why the error is?
 
Old 06-04-2014, 05:01 AM   #4
pan64
LQ Guru
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 9,767

Rep: Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886Reputation: 2886
for example here:
Quote:
+ echo '1002 + + '
you can see there are no real values just + signs. It happened because you tried to print the report inside the while loop and the input lines has not been (yet) evaluated.
 
1 members found this post helpful.
Old 06-04-2014, 08:25 AM   #5
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by pan64 View Post
for example here: you can see there are no real values just + signs. It happened because you tried to print the report inside the while loop and the input lines has not been (yet) evaluated.
Thanks a lot :-) i did the calculations outside the while loop and it worked. Thanks :-)
 
Old 06-04-2014, 09:43 AM   #6
grail
LQ Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 9,550

Rep: Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898Reputation: 2898
You could also look into all the duplication you have to minimise the code and make it a little clearer.

And is there really white space around the last value at all? Just the sed seems a bit of an overkill, especially the use of 'g' seeing you are removing space from the start and the end, these
positions only appear once so the 'g' is a little superfluous.
 
1 members found this post helpful.
Old 06-12-2014, 12:49 AM   #7
santosh0782
Member
 
Registered: Nov 2013
Posts: 132

Original Poster
Rep: Reputation: Disabled
Quote:
Originally Posted by grail View Post
You could also look into all the duplication you have to minimise the code and make it a little clearer.

And is there really white space around the last value at all? Just the sed seems a bit of an overkill, especially the use of 'g' seeing you are removing space from the start and the end, these
positions only appear once so the 'g' is a little superfluous.
oh yes, i'll remove the 'g' from sed. Thanks a lot :-)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
having trouble with php code giving a Parse error: syntax error, unexpected '>' ashevillan Programming 6 03-14-2013 11:37 AM
code giving segmentation fault Anuradha12345 Programming 3 08-10-2012 03:37 AM
LXer: Giving the code away LXer Syndicated Linux News 0 06-25-2012 01:20 PM
software installation without giving source code ravi_scorp Linux - Software 3 09-15-2009 04:46 PM
LXer: Giving Google a licence to code LXer Syndicated Linux News 0 11-02-2006 02:21 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:18 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration