Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
google site



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Reply
English Japanese Spanish French German Portuguese Italian Powered by Powered by Google
 
Search this Thread
  #1  
Old 07-29-2010
Registered User
 

Join Date: Jul 2010
Location: Chennai
Posts: 4
Thanks: 5
Thanked 0 Times in 0 Posts
Issue with using Expression inside SHELL

Hi,
i tried to execute the following script. I am having a issue with the expr operator i used.


Code:
[marcdev@dyl02019dat03 eipfeed]$ vi wordcount_check.sh
        set feedback off;
        set heading off;
        set verify off;
        select count(*) from marc_bulk_status where status = 'READY_TO_PROCESS';
        exit;
        END`
echo "number of files to processed $count"
totwordc=0
while [ "$count" -gt 0 ]
do
        file_path=`sqlplus -s prospect_stg/prospect_stg@mdmpt <<ENDSQL
        set feedback off;
        set heading off;
        set verify off;
        VARIABLE g_file_path VARCHAR2(400);
        EXECUTE :g_file_path :=  fn_get_filepath();
        PRINT g_file_path;
        exit;
        ENDSQL`
echo $file_path
wordc=`wc -l $file_path`
echo "record count and the files to be processed now is $wordc"
echo $totwordc
totwordc=`expr $totwordc + $wordc`
count=`expr $count - 1`
done
echo "total records in the $count files is $totwordc"
sqlplus -s prospect_stg/prospect_stg@mdmpt <<ENDSQL
set feedback off;
set heading off;
set verify off;
update marc_bulk_status set status = 'READY_TO_PROCESS'
where   status = 'BUILD_IN_PROGRESS';
commit;
exit;
ENDSQL

output:

Code:
[marcdev@dyl02019dat03 eipfeed]$ sh wordcount_check.sh
number of files to processed
         5
/marc_data/erepos/in/ERP_436_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_436_Request.csv
0
expr: syntax error
/marc_data/erepos/in/ERP_437_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_437_Request.csv
expr: syntax error
/marc_data/erepos/in/ERP_438_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_438_Request.csv
expr: syntax error
/marc_data/erepos/in/ERP_439_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_439_Request.csv
expr: syntax error
/marc_data/erepos/in/ERP_440_Request.csv
record count and the files to be processed now is 30 /marc_data/erepos/in/ERP_440_Request.csv
expr: syntax error
total records in the 0 files is
Total number of records in mparty_output.csv file is 430 /marc_data/erepos/src/mparty_output.csv
-------------------------------------------------------------------
And when i comment the line i am getting the output:
##totwordc=`expr $totwordc + $wordc`
 
Output:
[marcdev@dyl02019dat03 eipfeed]$ sh wordcount_check.sh
number of files to processed
         5
/marc_data/erepos/in/ERP_436_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_436_Request.csv
0
/marc_data/erepos/in/ERP_437_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_437_Request.csv
0
/marc_data/erepos/in/ERP_438_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_438_Request.csv
0
/marc_data/erepos/in/ERP_439_Request.csv
record count and the files to be processed now is 100 /marc_data/erepos/in/ERP_439_Request.csv
0
/marc_data/erepos/in/ERP_440_Request.csv
record count and the files to be processed now is 30 /marc_data/erepos/in/ERP_440_Request.csv
0
total records in the 0 files is 0
Total number of records in mparty_output.csv file is 430 /marc_data/erepos/src/mparty_output.csv

What might may be the problem with that expression?

Last edited by scottn; 07-29-2010 at 05:41 PM..
Sponsored Links
  #2  
Old 07-29-2010
Registered User
 

Join Date: Mar 2008
Posts: 2,350
Thanks: 8
Thanked 65 Times in 64 Posts
Please post the exact and complete script (within code tags) without anything else that may have been on the screen at the time.


One potential problem is with this line, but the output posted does not match this problem:

Code:
        ENDSQL`

It must not be indented:

Code:
ENDSQL`

The actual error message comes from this line:

Code:
wordc=`wc -l $file_path`

The result in ${wordc} is a number AND a filename:

Code:
100 /marc_data/erepos/in/ERP_436_Request.csv

We only seem to need the number, therefore parse the output of "wc -l":

Code:
wordc=`wc -l $file_path|awk '{print $1}'`


Last edited by methyl; 07-29-2010 at 08:13 PM.. Reason: Change quote to code tags because spaces not visible. Correct assorted typos.
The Following User Says Thank You to methyl For This Useful Post:
boopathyvasagam (4 Weeks Ago)
  #3  
Old 07-29-2010
fpmurphy's Avatar
Moderator
 

Join Date: Dec 2003
Location: /dev/ph
Posts: 2,477
Thanks: 0
Thanked 37 Times in 36 Posts
Another solution which does not require the use of awk is

Code:
wordc=`wc -l < $file_path`

If your shell supports it the more modern syntax is:

Code:
wordc=$(wc -l < $file_path)

The Following User Says Thank You to fpmurphy For This Useful Post:
boopathyvasagam (4 Weeks Ago)
Sponsored Links
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Awk inside Awk expression pepeli30 UNIX for Dummies Questions & Answers 2 12-03-2009 02:32 AM
Webalizer issue when inside script eyes_drinker Shell Programming and Scripting 0 01-09-2009 06:27 AM
Regular expression issue chriss_58 Shell Programming and Scripting 4 12-03-2008 12:39 PM
Awk - Using a Shell Variable in the Reg Expression not4google Shell Programming and Scripting 6 11-01-2006 09:42 AM
How to run unix commands in a new shell inside a shell script? hkapil Shell Programming and Scripting 2 01-04-2006 05:56 AM



All times are GMT -4. The time now is 09:17 PM.