If statement with unmatched condition


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting If statement with unmatched condition
# 1  
Old 04-03-2015
If statement with unmatched condition

Hi Gurus,

I'm facing some issues with multiple conditions in my if statement.

Code:
 
if (!($InputLine=~/^Date/)) && (!($fields[6] eq "VEN")) {

Above is the line troughing some syntax errors.

I am trying to avoid the below creteria lines to process in my logic.
  • Records starting with "Date"
  • Valie "VEN" in field 6
Syntaxually the above code looks correct. But not sure why it is giving copilation errors...

Could someone advice if i'm doing anything wrong pls?

Thanks
Venkat
# 2  
Old 04-03-2015
Is this part of a homework assignment?

What utility are you using to process this statement?

What diagnostic is it printing when you try to compile or run this code?

How are the variables $InputLine and $fields[] defined?
# 3  
Old 04-03-2015
It is part of a filtering records from a file using a perl sub routine

I'm getting below syntax error while running the sub routine

Quote:
syntax error at test_cal_ven_1.pl line 26, near ") {"
26th line is that IF statement...

$InputLine is taking the records in my input file.

Please find the below my sub routime...

Code:
 
open (FILENAME,"RAV_20150403_060000.dat");
$InputLine1=<FILENAME>;
while ($InputLine1 ne "") {
    # print $InputLine1;
    my $result = &derfun($InputLine1);
    #print  %$result;
    $InputLine1=<FILENAME>;
}
sub derfun {
    my ($InputLine) = @_ ;
    my $vol;
    my @fields;
    my $sId;
    chomp($InputLine);
    @fields = split /\t/,$InputLine;
    $vol = $fields[7];
    $sId = $fields[1];
    If  (!($InputLine=~/^Date/))  && ($fields[6] eq "VEN") {
        my $refA = {
            "c_id" => "1234",
            "src_ast" => "RAV-" . $sId,
            "vol" => $vol
        } ;
        return $refA;
    }
}

# 4  
Old 04-03-2015
You will need to put the condition into parenthesis:

Code:
if ((!($InputLine=~/^Date/)) && ($fields[6] eq "VEN")) {


Last edited by Walter Misar; 04-03-2015 at 05:49 AM..
# 5  
Old 04-03-2015
Thanks Masir for the reply...

Code:
 
if  ((!($InputLine=~/^Date/))  && (!($fields[6] eq "MYR"))) {

I need to un-filter the VEN records... hence i used above... It worked now...

Thanks everyone...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

<< unmatched error

Hi all, I want to call a plsql package that does not return any value. I am using the following script to do so: sqlplus $UserNamePwd <<EOF set head off begin test_pkg.procedure('$DebugFlag'); end; exit EOF if then log_message "procedure failed." exit 1 fi exit $? I... (2 Replies)
Discussion started by: reshma15193
2 Replies

2. Shell Programming and Scripting

Two condition in if statement

Hi, I need to put two condition in if statement, but it is not working. Please suggest. if ---------- Post updated at 07:05 AM ---------- Previous update was at 06:55 AM ---------- Also when i put below command in script it is not running, but manually it is running ... (4 Replies)
Discussion started by: learnbash
4 Replies

3. Shell Programming and Scripting

If condition and for loop within sed statement

Hi, I tried to go through a lot of online material but could not find concrete solution. My issues is like this : I've got a input file like this : <a> <startDate>19700101000000</startDate> <endDate>20300101000000</endDate> </a> ... (12 Replies)
Discussion started by: Shaishav Shah
12 Replies

4. Shell Programming and Scripting

Unmatched <<

Hi, I am running sinple ksh script . From some reason it failed on the following error: ./ogg_status.sh: syntax error at line 16 : `<<' unmatched Please advise. #!/usr/bin/ksh export ORACLE_HOME=/software/oracle/DB10gR2 export LD_LIBRARY_PATH=/software/oracle/DB10gR2/lib:/usr/lib... (4 Replies)
Discussion started by: yoavbe
4 Replies

5. UNIX for Dummies Questions & Answers

LINUX Multiple condition in IF Statement - Pls help

Hi All, I am trying to put multiple conditions in an IF Statement (using $$). the Linux script somehow doesnt like it. The logic I am trying to implement is as follows, 1. I will first search for DateFile.txt 2. If it exists & there is a P_BUS_DATE value in it, then assign the date value... (5 Replies)
Discussion started by: dsfreddie
5 Replies

6. Shell Programming and Scripting

An issue with condition statement in shell script

Hello forum members. please go through the below mentioned issue and let me know the right solution. I have to write a script which runs another script .the executable script take input parmeters.so iam writing the the script below . Sample Code:Begins #! /bin/ksh echo " enter... (2 Replies)
Discussion started by: rajkumar_g
2 Replies

7. Shell Programming and Scripting

Condition statement in perl

#!/usr/bin/perl $output1 = "/home/log.txt" $output2 = "/home/grep.txt" #Statement1 creates an output file called log.txt. #Statement2 greps a line from log.txt and store the result in grep.txt I want to create a condition where if the file grep.txt is empty repeat process. Thanks. (1 Reply)
Discussion started by: sureshcisco
1 Replies

8. Shell Programming and Scripting

`for' unmatched

:b:Hi guys, I am getting this error in this piece of code, Any help will be appreciate rypidoc.shl: syntax error at line 79 : `for' unmatched ##Determine if there is a file to process ls 3526*.dat > /dev/null 2>&1 if then exit fi for i in 3526*.dat do # Capture just the file... (2 Replies)
Discussion started by: rechever
2 Replies

9. UNIX for Dummies Questions & Answers

Multiple Condition If statement

Hi, I would like to create an IF statement where if a variable is equal to at least one of 2 (or more) values then the script proceeds. For example: TEST_VAR=2 if ; then echo success! else echo failure fi I understand that the above syntax is wrong but I feel it must be close. Any... (1 Reply)
Discussion started by: msb65
1 Replies

10. Shell Programming and Scripting

else unmatched

I'm getting an else unmatched error on the script below.. For info : SYDB is the database name entered as a param on the command line. #Check the DB name HBDB=`sql $SYDB <<_END_ | grep '^|' | grep -v dbase | sed 's/|//g' | sed 's/ //g' set autocommit on; \p\g set lockmode... (7 Replies)
Discussion started by: b.hamilton
7 Replies
Login or Register to Ask a Question