Condition problem


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Condition problem
# 8  
Old 05-06-2016
Wheres the input sample requested?
# 9  
Old 05-06-2016
Quote:
Originally Posted by znesotomayor
.
.
.
Code:
if ($SDEPT == 888 || $SDEPT == 0) && !($DEPT == 55 || $DEPT == 16 || $DEPT == 76); then

.
.
.
In shell syntax you'll have to use square brackets like if [ $SDEPT == ... ]
# 10  
Old 05-06-2016
Code:
here's my initial input sample
file1.txt
290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00
290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00
290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00
290,1663,52,9,0,0.00,34.60,0.00,9.00,0.00

i tried it using awk -F "," '($4 == 888 || $4 == 0) && !($3 == 55 || $3 == 16 || $3 == 76)' file1.txt >> DEPT

how do i put it on if statement?

TIA
# 11  
Old 05-06-2016
Agglomerating all your samples into on file, I got
Code:
awk -F, '
($4 == 888 || $4 == 0) && !($3 == 55 || $3 == 16 || $3 == 76)   {print "DEPT ", $3, $4, $0; next}
        {print "CLASS", $3, $4, $0}
' OFS="\t"  file
DEPT     43    888    290,1663,43,888,0,0.00,86.91,0.00,26.98,0.00
DEPT     52    0    290,1663,52,0,0,0.00,0.00,0.00,0.00,0.00
DEPT     52    888    290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00
CLASS    76    5    290,1663,76,5,0,0.00,86.91,0.00,26.98,0.00
CLASS    52    2    290,1663,52,2,0,0.00,0.00,0.00,0.00,0.00
CLASS    52    999    290,1663,52,999,0,0.00,34.60,0.00,9.00,0.00
CLASS    16    705    290,1663,16,705,0,0.00,34.60,0.00,9.00,0.00
CLASS    76    888    290,1663,76,888,0,0.00,86.91,0.00,26.98,0.00
CLASS    55    0    290,1663,55,0,0,0.00,0.00,0.00,0.00,0.00
DEPT     52    888    290,1663,52,888,0,0.00,34.60,0.00,9.00,0.00
CLASS    16    888    290,1663,16,888,0,0.00,34.60,0.00,9.00,0.00
DEPT     1    888    290,1663,1,888,0,0.00,34.60,0.00,9.00,0.00

Would this result come close to what you need?
# 12  
Old 05-06-2016
if there's a CLASS found on output how to change the filename from file1.txt to file1.txt_AREA_BY_CLASS?

TIA

---------- Post updated at 09:57 PM ---------- Previous update was at 09:50 PM ----------

i think it's covered Sir RudiC. the problem is how can i code it Smilie

TIA
# 13  
Old 05-06-2016
Try
Code:
awk -F, '
($4 == 888 || $4 == 0) && !($3 == 55 || $3 == 16 || $3 == 76)   {print > (FN "DEPT"); next}
                                                                {print > (FN "CLASS")}
' FN="file.txt_Area_by_"  file

# 14  
Old 05-06-2016
Hi Sir RudiC,

the output should be 1 only per file. On every file, if there's a record contains class it will automatically change the filename into file1.txt_area_by_class. if there's no class on the record it's file1.txt_area_by_dept.

TIA

Last edited by znesotomayor; 05-06-2016 at 11:18 AM..
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