multiple Logical statement


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers multiple Logical statement
# 1  
Old 10-03-2006
multiple Logical statement

hi I have following if condition
line_by_line="0000000000000ttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt ttttttt"

if [ `expr substr "$line_by_line" 1 13` == "0000000000000" ]
then
echo "Exclusion criteria"
else
echo "Not exclusion criteria"
fi
above condition works perfectley but if i add one more logical condition as below
line_by_line="00000000000000000000000000tttttttttttttttttttttttttttttttttttttttttttttttttttttttttttt tttttttttttttttttttt"

if [ `expr substr "$line_by_line" 1 13` == "0000000000000" || `expr substr "$line_by_line" 26 12` == "UA ITEM FROM" ]
then
echo "Exclusion criteria"
else
echo "Not exclusion criteria"
fi

it throws the error as
test_script.sh: line 4: tttttttttttt: command not found

any clue on above error
# 2  
Old 10-03-2006
try this

Code:
if [ `expr substr "$line_by_line" 1 13` == "0000000000000" -o `expr substr "$line_by_line" 26 12` == "UA ITEM FROM" ]

or

Code:
if [ `expr substr "$line_by_line" 1 13` == "0000000000000" ] || [ `expr substr "$line_by_line" 26 12` == "UA ITEM FROM" ]

# 3  
Old 10-03-2006
you can also use this

Code:
if [[ `expr substr "$line_by_line" 1 13` == "0000000000000"  ||   `expr substr "$line_by_line" 26 12` == "UA ITEM FROM" ]]

-o and -a options are used within single test brackets

&& and || are used withing double brackets
# 4  
Old 10-03-2006
Thanks Anubh ...it works...
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

How to apply the update statement in multiple servers on multiple dbs at a time .?

Hi , Can any please help the below requirement on all multiple servers and multiple dbs. update configuration set value='yes' ;1) the above statement apply on 31 Databases at a time on different Ip address eg : 10.104.1.12 (unix ip address ) the above ip box contains 4 db's eg : db... (2 Replies)
Discussion started by: venkat918
2 Replies

2. Shell Programming and Scripting

Multiple FOR;Singe DO statement

Hi guys, I'm trying to send variable commands from 2 different files but I'm not figuring out how to put 2 "i" variables into the command, can anyone help? This is what is done when I read only 1 file: for i in $(file1.txt);do echo "$i " I'm trying to echo 2 variables, matching the lines... (2 Replies)
Discussion started by: demmel
2 Replies

3. Shell Programming and Scripting

Using Logical Expression in an AWK statement

I'm would to create a script that would give me the results below. Please note the spaces in the log file are actually commas(",".) Log file Data 0:00 21:15 899 43 31 12 25.39 0:00 21:20 736 34 19 15 35.39 0:00 21:20 776 41 28 13 ... (3 Replies)
Discussion started by: ravzter
3 Replies

4. Shell Programming and Scripting

How to use logical operators in multiple if statement

Hi I want to send a status mail if daily or weekly or monthly batch completed or aborted. Here is the code. if && && || Else if && && || Else if && && || then mailx –s “Status Report” sumone@sumthing.com else print ”try again” Plz suggest the changes. (3 Replies)
Discussion started by: Avi
3 Replies

5. Shell Programming and Scripting

Multiple not statement in AWK

Hi I have a logfile that do grow large rapid, so I like to create a new one with needed info. For some reason the tail -d do not like to redirects its output to a file. tail -f /var/log/daemon.log | grep -vE '(snmpd|ntpd)' gives me real time log of all lines without "snmpd" and "ntpd" This... (4 Replies)
Discussion started by: Jotne
4 Replies

6. Shell Programming and Scripting

multiple if statement

#! /bin/csh set umr=UMR foreach i ( `ls`) set file_nm=$i set bh_nm=`echo $file_nm | cut -d"_" -f2` if($bh_nm !=$umr) then { set bh_ext=`echo $file_nm | cut -d"_" -f4` set bh_num_nm="$bh_nm $bh_ext a .txt" mv $file_nm $bh_num_nm } ... (3 Replies)
Discussion started by: jdsignature88
3 Replies

7. UNIX for Dummies Questions & Answers

issue with multiple logical operators

Hi, shell is /bin/ksh I am trying to do the following in my code.. but its showing me an error if ] && ] ]]; then echo "id is $ida and chk_dy is $chk_dy" fi the error I get is syntax error at line 23 : `"$ida"' unexpected I need to execute the... (2 Replies)
Discussion started by: nss280
2 Replies

8. Shell Programming and Scripting

Can you use logical operators in a case statement (bash)?

I'm pretty sure I already know the answer to this, but I want to make sure I'm not overlooking anything. I'm working on a log monitoring script and every 10 lines I want to display a summary of events. The thing is, there are a lot of possible events, that likely won't have happened, so I only want... (0 Replies)
Discussion started by: DeCoTwc
0 Replies

9. Shell Programming and Scripting

Multiple Logical Operator Issues ...

Hi folks I have a snippet of code Which is like this If ( ( A || B || C ) && D ) then Do some thing.... elif exit fi How to rephrase this and use it so I dont get any Errors ... Looking out for helpful replies .. Thanks & Regards Srikanth GR (1 Reply)
Discussion started by: srikanthgr1
1 Replies

10. Shell Programming and Scripting

Logical AND within a case statement ??

Hi there, probably a really simple question to answer but i cant seem to find it can I use a logical AND (&&) within a CASE statement ie (ps this is useless syntax but youll get the idea case "$var1","$var2" in 'Billy' && 'Bobby') ... (1 Reply)
Discussion started by: hcclnoodles
1 Replies
Login or Register to Ask a Question