Combining Expressions


 
Thread Tools Search this Thread
Top Forums UNIX for Dummies Questions & Answers Combining Expressions
# 1  
Old 02-24-2009
Question Combining Expressions

Hi there,

I'm having some trouble with a script were I want 2 expressions to evaluate to true before my if loop will continue...

if [ `echo $line|grep "string"` -a $var -eq 1 ] ; then

Both these expressions work on their own, but not when combined. What am I doing wrong?

Regards
davewg

Smilie
# 2  
Old 02-24-2009
What error did you get? Maybe try this:

Code:
if [[ `echo $line|grep "string"` && $var -eq 1 ]] ; then

# 3  
Old 02-24-2009
what's an "if loop"?
# 4  
Old 02-24-2009
`echo $line|grep "string"`
what are you trying to check here?
the above command will return a value. Its not a condition.
Are you trying to check " if $line has value string or $var equal to 1"
If this is the case check status of the above command and use that as a condition in IF statement.
echo $line|grep "string"
cmd_status=$?
if [ cmd_status -eq 0 -a $var -eq 1 ] ; then
# 5  
Old 02-24-2009
Quote:
Originally Posted by zaxxon
What error did you get? Maybe try this:

Code:
if [[ `echo $line|grep "string"` && $var -eq 1 ]] ; then

Hi, I was getting 'too many arguments' error message, but your recomendation works a treat! Thanks for your help Smilie
# 6  
Old 02-24-2009
Tools

Quote:
Originally Posted by vgersh99
what's an "if loop"?
Smilie

Hi, thanks for your response, that's really helpful. This is the 'UNIX for Dummies' forum - "All UNIX and Linux newbies welcome" - hence there perhaps be a slight lack of understanding of everything unix related, and perhaps even sometimes, the occasional gramatical mistake or ommition when posting a thread requesting help. I would assume this is to be expected, and really clever, cool people like you would overlook such minor oversights and simply offer the help and assistance us newbies are requesting with your vastly superior knowledge that inevitably makes you such a big hit with the ladies. Smilie

I wish I was like you.

Smilie
# 7  
Old 02-24-2009
Quote:
Originally Posted by davewg
Smilie

Hi, thanks for your response, that's really helpful. This is the 'UNIX for Dummies' forum - "All UNIX and Linux newbies welcome" - hence there perhaps be a slight lack of understanding of everything unix related, and perhaps even sometimes, the occasional grammatical mistake or ommition when posting a thread requesting help. I would assume this is to be expected, and really clever, cool people like you would overlook such minor oversights and simply offer the help and assistance us newbies are requesting with your vastly superior knowledge that inevitably makes you such a big hit with the ladies. Smilie

I wish I was like you.

Smilie
This is perfectly understood and expected.
BTW, there's no need to reveal my personal secrets in public!
 
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Regular expressions

I need to pick a part of string lets stay started with specific character and end with specific character to replace using sed command the line is like this:my audio book 71-skhdfon1dufgjhgf8.wav' I want to move the characters beginning with - end before. I have different files with random... (2 Replies)
Discussion started by: XP_2600
2 Replies

2. Homework & Coursework Questions

Boolean expressions for If's

1. The problem statement, all variables and given/known data: Im experimenting with if expressions for an assignment. What i want to do is check if an input of read x y z will be checked against x for 1-999 for y for and for z for 1-999. Am i doing this right? or perhaps you could tell me... (0 Replies)
Discussion started by: Ren_kun
0 Replies

3. Shell Programming and Scripting

Help with regular expressions

I have a file that I'm trying to find all the cases of phone number extensions and deleting them. So input file looks like: abc x93825 def 13234 x52673 hello output looks like: abc def 13234 hello Basically delete lines that have 5 numbers following "x". I tried: x\(4) but it... (7 Replies)
Discussion started by: pxalpine
7 Replies

4. Shell Programming and Scripting

Need help with Regular Expressions

Hi, In ksh, I am trying to compare folder names having -141- in it's name. e.g.: 4567-141-8098 should match this expression '*-141-*' but, -141-2354 should fail when compared with '*-141-*' simlarly, abc should fail when compared with '*-141-*' I tried multiple things but nevertheless,... (5 Replies)
Discussion started by: jidsh
5 Replies

5. UNIX for Dummies Questions & Answers

Unix Expressions

Hi to all, this is my first time in the forum...and I know some basic's about UNIX... I want to write an expression to validate a field. field is varchar2, length is 5, can be from '00001' to '99999'. no loops or if condition, just check the value if between these two numbers it is OK if it is... (2 Replies)
Discussion started by: 786habeeb
2 Replies

6. UNIX for Advanced & Expert Users

Regular Expressions

Hi, below is a piece of code written by my predecessor at work. I'm kind of a newbie and am trying to figure out all the regular expressions in this piece of code. It is really a tough time for me to figure out all the regular expressions. Please shed some light on the regular expressions... (3 Replies)
Discussion started by: ramky79
3 Replies

7. Shell Programming and Scripting

regular expressions

Hello, Let say I have a string with content "Free 100%". How can extract only "100" using ksh? I would this machanism to work if instead of "100" there is any kind of combination of numbers(ex. "32", "1238", "1"). I want to get only the digits. I have written something like this: ... (4 Replies)
Discussion started by: whatever
4 Replies

8. UNIX for Dummies Questions & Answers

regular expressions

Hi Gurus, I need help with regular expressions. I want to create a regular expression which will take only alpha-numeric characters for 7 characters long and will throw out an error if longer than that. i tried various combinations but couldn't get it, please help me how to get it guys. ... (2 Replies)
Discussion started by: ragha81
2 Replies

9. Shell Programming and Scripting

regular expressions

Hi, can anyone advise me how to shorten this: if || ; then I tried but it dosent seem to work, whats the correct way. Cheers (4 Replies)
Discussion started by: jack1981
4 Replies

10. Shell Programming and Scripting

Regular Expressions

How can i create a regular expression which can detect a new line charcter followed by a special character say * and replace these both by a string of zero length? Eg: Input File san.txt hello hi ... (6 Replies)
Discussion started by: sandeep_hi
6 Replies
Login or Register to Ask a Question