Condition problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Condition problem
# 15  
Old 05-06-2016
Maybe this example helps use to make comparing little easier in shell. You can add breaks as you like.
Code:
for file in *.txt
do
    stat="DEPTH"
    while IFS="," read f1 f2 DEPT SDEPT rest
    do
        flag="DEPTH"
        ## between ((   and ))   you can use syntax same as like in C or ...
        ((   ( DEPT != 888 )  && ( DEPT !=0 )   ))  && flag="C1"    # && break # if like to break
       # if the 3rd column contains 55, 16, 76 and 4th column = 888 or 0 then it's the same as by CLASS
       # so write rule as it has been written:
         ((  ( DEPT == 55 || DEPT == 16 || DEPT == 76 ) && ( SDEPT == 888 || SDEPT == 0 )  )) && flag="C2"
       # if the 3rd column contains 55, 16, 76 and 4th column not equal 888 or 0 then it's the same as by CLASS
       # so write rule as it has been written:
         ((  ( DEPT == 55 || DEPT == 16 || DEPT == 76 ) && ( SDEPT != 888 && SDEPT != 0 )  )) && flag="C3"
        echo "      $flag - $f1 $f2 d:$DEPT sd:$SDEPT $rest"
        [ "$flag" != "DEPTH" ] && stat="CLASS"
    done < $file
    echo "$file - $stat"
done

(( ( DEPT != 888 ) && ( DEPT !=0 ) )) && flag="CLASS"
is same as
Code:
if ((   ( DEPT != 888 )  && ( DEPT !=0)   ))  
then
   flag="CLASS"
fi


Last edited by kshji; 05-07-2016 at 03:48 AM..
This User Gave Thanks to kshji For This Post:
# 16  
Old 05-07-2016
hi kshji,

how about the 3 condition? 55,76 and 15?
# 17  
Old 05-07-2016
In reaction to a recent PM:


Sorry but I'm stuck.

I'm afraid I can't help any further unless you give a clear picture of the overall problem. Appreciating that English might not be your first language (it's not mine either) and all the possible problems herewith, I do not understand what you need and where you're stuck.

In my post#4 I asked you to rephrase the problem AND supply decent, meaningful samples, which you did reluctantly only, and in pieces. Why can't you show the entire picture and the underlying structures?
- OS and shell used?
- What tools would be preferred (shell? awk/sed/perl? other?) or excluded?
- How many input files (you supplied several but different "file1.txt")?
- How many output files per input file?
- What's the logics/algorithms connecting the two?
- Attempts at solving the problem?
- Errors/messages/behaviour encountered when running either attempt?

Without a clear understanding of the situation, everybody (not only) in here will be shooting in the dark (which I did multiple times), and coming up with a fit solution would be sheer coincidence.

Did you even consider adapting the proposals supplied?
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

If condition problem

Hi All, I am using below if condition to check whether null is passed as a parameter to the program if or ; then echo "ABC">>$FILE else echo "CDF">>$FILE fi However it is saying me null=null command not found . Please help me with this (9 Replies)
Discussion started by: Hypesslearner
9 Replies

2. Shell Programming and Scripting

Problem with IF condition .

Hi i am writing a script where i am running , 5 scripts together in 1 script . Now what i want is when these 5 scripts run completely , i should execute some other commands like i have compile the data etc. I have have 5 echo statements at the end of all those scripts . Like echo "1 is done" in... (1 Reply)
Discussion started by: honey26
1 Replies

3. Shell Programming and Scripting

If condition problem

Hi, I need to use if condition for search a file pattern on a particular location. cd $file_Path if || then do this else do that fi Can someone help me with the if part, how i can put those conditions? make sure format should be *.file* and *.file file is a keyword which i... (5 Replies)
Discussion started by: amit.mathur08
5 Replies

4. Shell Programming and Scripting

Problem in if condition

Hi all, I have task to delete two different files from all file system. one is core file & other is old file. i can delete core file but for old file i have to mv in different location. i wrote a script but it is not working. i have a two variables in this script first one is delcnt &... (6 Replies)
Discussion started by: dravi_laxmi
6 Replies

5. Shell Programming and Scripting

Problem in using AND OR condition together

a=rhino b=crocodil c=testsc if && "$c" = testsc ] then echo "Test #5 succeeds." else echo "Test #5 fails." fi i need to test or condition before check the output with AND condition. ur help is much appreciated... (11 Replies)
Discussion started by: gokulraj23
11 Replies

6. Shell Programming and Scripting

problem in if then else condition

Hi , I am trying the following simple script . But it is always giving 1 output. Dont know why #!/bin/sh find . -name "a.log" if ; then echo "1" else echo "0" fi Kindly advice. it is giving 1 output even when the a.log file is not there (26 Replies)
Discussion started by: himvat
26 Replies

7. Shell Programming and Scripting

problem in if condition

hi, actully i need the belp for the below. host_list=" Host1 host2 host3 host4 " n=`hostname` i need to put the condition like the below if n is among the host mention in the host_list if then #some stugg else # some other stuff fi (1 Reply)
Discussion started by: mail2sant
1 Replies

8. Shell Programming and Scripting

problem with if condition

hi, :) pls consider the following if statement if //g') ] then ........ else ....... when i execute the script i am getting the following error '(' unexpected I am not able to find the mistake. could anybody tell where i did mistake. cheers RRK (13 Replies)
Discussion started by: ravi raj kumar
13 Replies

9. Shell Programming and Scripting

If condition problem

Hi Guys, I want to use if conition for my script. Before I used it tried it with some small test scripts. But it was not succeeded. My script and screen output as follows, Script: echo 'Do you think Yes or No (y/n) : ' read ans echo You input anser as $ans ans1=y if ( $ans == $ans1... (5 Replies)
Discussion started by: maheshsri
5 Replies
Login or Register to Ask a Question