A special compare


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting A special compare
# 1  
Old 05-15-2013
A special compare

Hi

I use the following compare

Code:
if [[ "${ben_lfw[@]}" == *"$vl"* ]]; then ...

Can anyone tell me, how to code the compare for unequal? I got no results from google searches.

Any hint or tip is welcome.

Regards
Lazy

Last edited by Scott; 05-15-2013 at 02:43 PM.. Reason: Code tags, please...
# 2  
Old 05-15-2013
Use =~ in place of ==

Quote:
string =~ ere
True if string matches the pattern ~(E)ere where ere is an extended regular expression.
Code:
$ echo $X
12xx34
$ [[ $X =~ xx ]] && echo Yes  
Yes

# 3  
Old 05-15-2013
Quote:
Originally Posted by Scott
Use =~ in place of ==
I think you may have misunderstood the OP's problem statement. They are using == to test for equality and are asking how to test for inequality. The inverse of == is !=, not =~.

== and != treat the right operand as a pattern (glob). =~ has the same sense of equality as == but it expects an extended regular expression instead of shell pattern matching notation.

Regards,
Alister
# 4  
Old 05-15-2013
Quote:
Originally Posted by alister
I think you may have misunderstood the OP's problem statement.
Not really. The subject title and code, as given, suggested more an attempt to match against a non-exact string that negate a match.
# 5  
Old 05-15-2013
Scott:
I've already been wrong a couple of times today. There is no way it is happening again! Smilie All joking aside ...

lazybaer:
If you need to switch from shell pattern notation to extended regular expressions, you need to carefully consider the transition. Certain characters, such as dot, asterisk, or question mark (among others), have a different meaning and simply backslash escaping is insufficient.

Regards,
Alister
This User Gave Thanks to alister For This Post:
# 6  
Old 05-16-2013
Thanks Allister

!= is working

Lazy
Login or Register to Ask a Question

Previous Thread | Next Thread

8 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Special character $$

Hi, on ksh What does the following do? grep -v "toolbox" $home_oracle/.profile >$home_oracle/.profile.$$ Thanks. Please use CODE tags as required by forum rules! (3 Replies)
Discussion started by: big123456
3 Replies

2. UNIX for Dummies Questions & Answers

Compare data - Match first column and compare second

Hi guys, looking for some help with a way to compare data in two files but with some conditions. example, File 1 consists of site1,10.1.1.1 site2,20.2.2.2 site3,30.3.3.3 File 2 contains site1,l0.1.1.1 site2,50.1.1.1 site3,30.3.3.3 site4,40.1.1.1 I want to be able to match the... (1 Reply)
Discussion started by: mutley2202
1 Replies

3. Shell Programming and Scripting

Require compare command to compare 4 files

I have four files, I need to compare these files together. As such i know "sdiff and comm" commands but these commands compare 2 files together. If I use sdiff command then i have to compare each file with other which will increase the codes. Please suggest if you know some commands whcih can... (6 Replies)
Discussion started by: nehashine
6 Replies

4. UNIX for Dummies Questions & Answers

I need a special print

I have this: \2009_may\05-04-2009\05-04-2009(74) \2009_may\05-04-2009\05-04-2009(74)\05-04-2009(74)_0-999 \2009_may\05-04-2009\05-04-2009(74)_left \2009_may\05-04-2009\05-04-2009(74)_left\05-04-2009(74) \2009_may\05-04-2009\05-04-2009(74)_right... (3 Replies)
Discussion started by: kenneth.mcbride
3 Replies

5. Shell Programming and Scripting

UrgentPlease: compare 1 value with file values eliminating special characters

Hi All, I have file i have values like ---- 112 113 109 112 109 I have another file cat supplierDetails.txt ------------------------- 112|MIMUS|krishnaveni@google.com 113|MIMIRE|krishnaveni@google.com 114|MIMCHN|krishnaveni@google.com 115|CEL|krishnaveni@google.com... (10 Replies)
Discussion started by: kittusri9
10 Replies

6. Shell Programming and Scripting

Compare two arrays in sh or compare two fields

I want a soultion to compare two arrays in sh with an easy way.I want a solution to synchrose users between different AIX servers where no NIS is available. All users are meant to be same on all 10 servers. So the approach is to consider first server as master user repository and whatever the users... (0 Replies)
Discussion started by: rijeshpp
0 Replies

7. Programming

special character ?

hey there im a bit stuck on executing commands that include the special character '?'. can someone recommend a way on how i would be able to execute it?? i thought the glob function could be useful (still mite be) but upon entering the command 'ls pars?' it listed all the files in the... (1 Reply)
Discussion started by: mile1982
1 Replies

8. UNIX for Dummies Questions & Answers

special characters

I have one file which is named ^? ( the DEL character ) I'd like to know how to rename or copy the file by using its i-node number TYIA (2 Replies)
Discussion started by: nawnaw
2 Replies
Login or Register to Ask a Question