Sponsored Content
Full Discussion: Condition problem
Top Forums Shell Programming and Scripting Condition problem Post 302972538 by kshji on Friday 6th of May 2016 12:29:58 PM
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:
 

9 More Discussions You Might Find Interesting

1. 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

2. 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

3. 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

4. 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

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 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

7. 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

8. 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

9. 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
STAG-DB(1p)						User Contributed Perl Documentation					       STAG-DB(1p)

NAME
stag-db - persistent storage and retrieval for stag data (xml, sxpr, itext) SYNOPSIS
stag-db -r person -k social_security_no -i ./person-idx myrecords.xml stag-db -i ./person-idx -q 999-9999-9999 -q 888-8888-8888 DESCRIPTION
Builds a simple file-based database for persistent storage and retrieval of nodes from a stag compatible document. Imagine you have a very large file of data, in a stag compatible format such as XML. You want to index all the elements of type person; each person can be uniquely identified by social_security_no, which is a direct subnode of person The first thing to do is to build an index file, which will be stored in your current directory: stag-db -r person -k social_security_no -i ./person-idx myrecords.xml You can then use the index "person-idx" to retrieve person nodes by their social security number stag-db -i ./person-idx -q 999-9999-9999 > some-person.xml You can export using different stag formats stag-db -i ./person-idx -q 999-9999-9999 -w sxpr > some-person.xml You can retrieve multiple nodes (although these need to be rooted to make a valid file) stag-db -i ./person-idx -q 999-9999-9999 -q 888-8888-8888 -top personset Or you can use a list of IDs from a file (newline delimited) stag-db -i ./person-idx -qf my_ss_nmbrs.txt -top personset ARGUMENTS -i INDEXFILE This file will be used as the persistent index for storage/retrieval -r RELATION-NAME This is the name of the stag node (XML element) that will be stored in the index; for example, with the XML below you may want to use the node name person and the unique key id <person_set> <person> <id>...</id> </person> <person> <id>...</id> </person> ... </person_set> This flag should only be used when you want to store data -k UNIQUE-KEY This node will be used as the unique/primary key for the data This node should be nested directly below the node that is being stored in the index - if it is more that one below, specify a path This flag should only be used when you want to store data -u UNIQUE-KEY Synonym for -k -p PARSER This can be the name of a stag supported format (xml, sxpr, itext) - XML is assumed by default It can also be a module name - this module is used to parse the input file into a stag stream; see Data::Stag::BaseGenerator for details on writing your own parsers/event generators This flag should only be used when you want to store data -q QUERY-ID Fetches the relation/node with unique key value equal to query-id Multiple arguments can be passed by specifying -q multple times This flag should only be used when you want to query data -top NODE-NAME If this is specified in conjunction with -q or -qf then all the query result nodes will be nested inside a node with this name (ie this provides a root for the resulting document tree) -qf QUERY-FILE This is a file of newline-seperated IDs; this is useful for querying the index in batch -keys This will write a list of all primary keys in the index -w WRITER This format will be used to write the data; can be any stag format (xml, sxpr, itext) - default XML. Can also be a module that catches the incoming stag event stream and does something with it (for example, this could be a module you write yourself that transforms the stag events into HTML) SEE ALSO
Data::Stag For more complex stag to database mapping, see DBIx::DBStag and the scripts stag-storenode selectall_xml perl v5.10.0 2008-12-23 STAG-DB(1p)
All times are GMT -4. The time now is 05:00 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy