![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| How to giv two conditions in IF statement..?? | RRVARMA | Shell Programming and Scripting | 6 | 04-25-2008 06:33 AM |
| problem with if, while, for conditions | kittusri9 | Shell Programming and Scripting | 3 | 04-24-2008 06:15 AM |
| reduce the or conditions | hitmansilentass | Shell Programming and Scripting | 8 | 05-03-2007 02:27 PM |
| multiple conditions in if/then | grandtheftander | UNIX for Dummies Questions & Answers | 4 | 07-21-2006 10:58 AM |
| if statement with two conditions | cin2000 | Shell Programming and Scripting | 1 | 01-23-2006 12:21 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
if statement with two conditions -e, &&
Wow I'm so zoned out I don't even know if I posted this question up already (I couldn't find it in my book marks or in "yesterday's" post).
My question is, I'm writing a korn script that does something like the following, but I don't yet completely understand the syntax. I need to check that the first field equals a string and that the second string equals a space. This isn't working -- is it right or wrong? PHP Code:
|
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
problem
Could u please provide us with the file that u r using
As the result depends upon wether the file contains 1 record or many |
|
#3
|
|||
|
|||
|
apologies
Ah yes, of course. Let me type out the larger picture so you can see how it's working.
The ls.txt is a cut listing of filenames (one filename per line). As I'm opening each file, which happen to be all fixed-length csv files, I'm cutting the first field and the fifth field. The following would be an example of two records (each line in each fixed-length csv file is a record with aproximately 32 fields). I have isolated the two fields for you. Example fields (the forum deletes extra spaces so it would be easier I think if I describe it instead: FIELD1 is in columns 2-4 (a string of 3 letters), and the the second column aka FIELD5 can either be filled with a one digit number (1-9) or a single space (" "). PHP Code:
Last edited by yongho; 06-14-2005 at 07:29 AM. |
|
#4
|
||||
|
||||
|
Code:
#!/bin/ksh
..........
..........
typeset -i count
if [ "$FIELD1" = 'PBR' -a "$FIELD2" = ' ' ]; then
count=$((count + 1))
fi
Last edited by vgersh99; 06-14-2005 at 07:37 AM. |
|
#5
|
|||
|
|||
|
HrrmMm..
Question: I just started learning shell scripting a few days ago and I was under the assumption that you didn't need to typeset anything.
One of my previous counters looked like this (in a while statement, not an if statement: var1=`expr $var1 + $var2` ..and it worked. But when I tried the expr command in the if statement, it didn't increment at all. Would you know why this is? Could it be because once you enter an if statement, you must use different rules? Last edited by yongho; 06-14-2005 at 07:54 AM. |
|
#6
|
||||
|
||||
|
Quote:
if you don't, count=$((count + 1)) becomes count=$(($count + 1)) Quote:
Quote:
are you saying that the 'expr ' increment did not work, but the 'count=$((count+1))' did? there must be something else different in your 'while' loop. is your 'while' loopbeing piped with data? |
|
#7
|
|||
|
|||
|
i think you're on to something..
Quote:
Here's the big picture. PHP Code:
edit: Hmm.... You know what, let me work on this for another hour and come back and tell you if it's still broken. Last edited by yongho; 06-14-2005 at 11:54 AM. |
|||
| Google The UNIX and Linux Forums |