How to implement "not in" logic in UNIX script?


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting How to implement "not in" logic in UNIX script?
# 1  
Old 01-27-2014
How to implement "not in" logic in UNIX script?

Hi Gurus,

I need use "not in " logic in my script, like below

Code:
if $name not in exception_file_list, then do something.

anyone can help out this?

Thanks in advance.

Last edited by ken6503; 01-27-2014 at 12:22 PM..
# 2  
Old 01-27-2014
Hello,

Kindly use the code tags while posting as per forum rules.

Here is an exmaple which may help you.


Code:
cat check_specific_txt.ksh
 
value=`cat make_test.ksh | grep XYZ"`
if [[ -z ${value} ]]
then
echo "Not match"
else
echo "Match found"
fi
Not match



Thanks,
R. Singh
This User Gave Thanks to RavinderSingh13 For This Post:
# 3  
Old 01-27-2014
Quote:
Originally Posted by RavinderSingh13
Hello,

Kindly use the coee tags whiule posting as per forum rules.

Here is an exmaple which may help you.


Code:
cat check_specific_txt.ksh
 
value=`cat make_test.ksh | grep XYZ"`
if [[ -z ${value} ]]
then
echo "Not match"
else
echo "Match found"
fi
Not match

Thanks for your quick response, Sorry I didn't put code tag in my initial posting.



Thanks,
R. Singh
# 4  
Old 01-27-2014
Hai Ken Here is an example might help you

Code:
$ cat Jan.txt
10  Jan 100
30  Jan 300
50  Jan 500

$ if ! grep Feb Jan.txt >/dev/null; then echo "yes"; else echo "No"; fi
yes

This User Gave Thanks to Akshay Hegde For This Post:
# 5  
Old 01-27-2014
Quote:
Originally Posted by Akshay Hegde
Code:
$ if ! grep Feb Jan.txt >/dev/null; then echo "yes"; else echo "No"; fi
yes

Instead of redirecting to /dev/null, consider using grep -q. -q tells grep that you are only interested in the exit status, so if a match is found grep can exit immediately, avoiding unnecessary i/o.

Regards,
Alister
# 6  
Old 01-27-2014
Hi Akshay & R. Singh
Both ways work perfect.

Thank you very much.

Have a nice day.
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Bash script - Print an ascii file using specific font "Latin Modern Mono 12" "regular" "9"

Hello. System : opensuse leap 42.3 I have a bash script that build a text file. I would like the last command doing : print_cmd -o page-left=43 -o page-right=22 -o page-top=28 -o page-bottom=43 -o font=LatinModernMono12:regular:9 some_file.txt where : print_cmd ::= some printing... (1 Reply)
Discussion started by: jcdole
1 Replies

2. Shell Programming and Scripting

How to implement "sleep" in Perl ?

I tried, #!/usr/bin/perl print "check 1"; print "check 2"; sleep(5); The above works fine but sleep takes the higest priority. Looks weird In above program "sleep" executes first and then "print" comes next. I would like the program to be executed in "sequence" , Print at first and then... (3 Replies)
Discussion started by: frintocf
3 Replies

3. Shell Programming and Scripting

How to implement the logical express --- A(B+C) within single "if" statment in shell script?

On Linux OS, bash environment, I want implement the following code: if && ( || ) A,B,C represents some compare conditions. How to realize it ? Thanks! (1 Reply)
Discussion started by: qcmao
1 Replies

4. UNIX for Dummies Questions & Answers

Unix "look" Command "File too large" Error Message

I am trying to find lines in a text file larger than 3 Gb that start with a given string. My command looks like this: $ look "string" "/home/patrick/filename.txt" However, this gives me the following message: "look: /home/patrick/filename.txt: File too large" So, I have two... (14 Replies)
Discussion started by: shishong
14 Replies

5. Shell Programming and Scripting

awk command to replace ";" with "|" and ""|" at diferent places in line of file

Hi, I have line in input file as below: 3G_CENTRAL;INDONESIA_(M)_TELKOMSEL;SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL My expected output for line in the file must be : "1-Radon1-cMOC_deg"|"LDIndex"|"3G_CENTRAL|INDONESIA_(M)_TELKOMSEL"|LAST|"SPECIAL_WORLD_GRP_7_FA_2_TELKOMSEL" Can someone... (7 Replies)
Discussion started by: shis100
7 Replies

6. Shell Programming and Scripting

Execution problems with the jar -tvf command and "if" logic

Hi, I am reading a directory that has a list of jar files. I am searching these files for specific keywords. What i would like to do is write the address of the jar file to a new file if the search result is returned as false. For example; /home/user/JarDirectory/Examplefile.jar ... (2 Replies)
Discussion started by: crunchie
2 Replies

7. Shell Programming and Scripting

Unix commands delete all files starting with "X" except "X" itself. HELP!!!!?

im a new student in programming and im stuck on this question so please please HELP ME. thanks. the question is this: enter a command to delete all files that have filenames starting with labtest, except labtest itself (delete all files startign with 'labtest' followed by one or more... (2 Replies)
Discussion started by: soccerball
2 Replies

8. UNIX for Advanced & Expert Users

Commands on Digital Unix equivalent to for "top" and "sar" on other Unix flavour

Hi, We have a DEC Alpha 4100 Server with OSF1 Digital Unix 4.0. Can any one tell me, if there are any commands on this Unix which are equivalent to "top" and "sar" on HP-UX or Sun Solaris ? I am particularly interested in knowing the CPU Load, what process is running on which CPU, etc. ... (1 Reply)
Discussion started by: sameerdes
1 Replies
Login or Register to Ask a Question