Issue with using Expression inside SHELL


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Issue with using Expression inside SHELL
# 1  
Old 07-29-2010
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 Scott; 07-29-2010 at 06:41 PM..
# 2  
Old 07-29-2010
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 09:13 PM.. Reason: Change quote to code tags because spaces not visible. Correct assorted typos.
This User Gave Thanks to methyl For This Post:
# 3  
Old 07-29-2010
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)

This User Gave Thanks to fpmurphy For This Post:
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Advanced & Expert Users

Passing parameter inside the expression

Hello, i need to pass the variable in place of pwd. how to display variable in the bleow syntax. suppose, passwd="test", then 'id/$passwd..... FEDFlagResult=`sqlplus -S 'id/pwd@(DESCRIPTION= (ADDRESS=(PROTOCOL=TCP)(HOST=localhost)(PORT=1643))(CONNECT_DATA= (SID=peta1)))'<< EOF select... (4 Replies)
Discussion started by: balareddy
4 Replies

2. Shell Programming and Scripting

Issue with ls command inside script

Hi , DIR1 has only one file with .txt extension , trying to get the size of that file using the following script #!/bin/ksh foldr_1="/etc/DIR1" #echo "$foldr_1" sze_fdr1=$(ls -ltr foldr_1/*.txt |awk '{ print $5 }') echo "$sze_fdr1" After executing the above script getting... (1 Reply)
Discussion started by: smile689
1 Replies

3. Shell Programming and Scripting

Issue with accessing value inside while loop, outside it

Hi, GetName() { if then echo " Please enter the name: " read Name tempvar=0 while read line do if then tempvar=`expr $tempvar + 1` echo $tempvar ... (10 Replies)
Discussion started by: rituparna_gupta
10 Replies

4. Shell Programming and Scripting

Command substitution inside of a variable expression (AIX, KORN)

Hello all. This is my first post/question on this site. I’m a new Systems Analyst with previous experience with BASH. Although now I'm using AIX, and I’m trying to get a feel for the Korn shell (for those of you that don’t know AIX only uses the KORN shell). I hope I put this into the correct... (10 Replies)
Discussion started by: sydox
10 Replies

5. Shell Programming and Scripting

perl regular expression not inbetween issue

Dear All, perl -e 'if($ARGV =~ /\A^{10}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '1234567899' Valid string perl -e 'if($ARGV =~ /\A^{8}\z/){print "Valid string\n"}else{print "Invalid string\n"}' '12345678' Valid string individually both works, anyway to combine both... (3 Replies)
Discussion started by: jimmy_y
3 Replies

6. Shell Programming and Scripting

wildcard inside regular expression for grep

Hi, I'm on a Linux machine with a bash shell. I have some apache logs from where I want to extract the lines that match this pattern : "GET /dir1/dir2/dir3/bt_sx.gif HTTP/1.1" but where "/dir1/dir2/dir3/bt_sx" may vary , so I would like to grep something like cat apache.log | grep "\"GET... (2 Replies)
Discussion started by: black_fender
2 Replies

7. Shell Programming and Scripting

Regular expression inside case statement notworking

I have the following script: For catching errors like: But the regular expression ERROR*memory inside case doesn't seem to be working. The output of bash -x scriptname is: Please help (5 Replies)
Discussion started by: proactiveaditya
5 Replies

8. Shell Programming and Scripting

AWK script issue for the part regular expression

Hi I am having a file as shown below FILE 1 TXDD00, TXDD01, TXDD02, TXDD03, TXDD04, TXDD05, TXDD06, TXDD07, TXDD08, TXDD09, TXDD10, TXDD11, TXDD12, TXDD13, TXDD14, TXDD15, TXDD16, TXDD17, TXDD18, TXDD19, TXDDCLK, TXDJTAGAMPL0, TXDJTAGAMPL1,... (3 Replies)
Discussion started by: jaita
3 Replies

9. Shell Programming and Scripting

Webalizer issue when inside script

hello gurus, When i run the command on shell webalizer -p -n mydomain.com -c /path/to/my/log/webalizer.conf it works fine and it creates stats for the given mydomain.com in the target output directory but when i put it in a script same command and parameters but it goes weird and it... (0 Replies)
Discussion started by: eyes_drinker
0 Replies

10. Shell Programming and Scripting

Regular expression issue

Hi, I have the following string: $string= BG_1_12345_?_XX.SVF The '?' means that any character could be in that position. If from a file i will read the string $str=12345 how can i modify the $str in order to be $str=$string. Best regards, Christos (4 Replies)
Discussion started by: chriss_58
4 Replies
Login or Register to Ask a Question