|
|
|
|
google site
|
|||||||
| Forums | Register | Blog | Man Pages | Forum Rules | Links | Albums | FAQ | Users | Calendar | 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 and shell scripting languages here. |
![]() |
|
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|||
|
how can i use two or multiple statements in the if part
of an awk code for example i want to check two flag if they are true i will write some print operations and increase the counter. here is the c version of the code that i want to write: counter=0; if (flag1==1 && flag2==0) { printf("true\n"); counter=counter+1; flag1=0; } else printf("false"); how can i do the same operation using awk? |
| Sponsored Links |
|
|
|
|||
|
i dont think that, its just like i said.
(at least i couldnt make it work) let me ask my question with a different example. i wrote an awk code as follows, and i cannot make it work, my guess is: the problem stems from the compund statements. whats wrong with this code? for file in TESTFILE*; do counter1=0; counter2=0; awk -F" " '{ if ( $1 = /flag1/ ) { print "TRUE"; $2="true"; counter1=$counter1+1} else { print "FALSE"; counter2=$counter2+1 }}' $file>testfileoutput done print $counter1 print $counter2 |
|
||||
|
Awk tests in the form Code:
$1 == "foo" && $2 == "bar" are perfectly acceptable, as is Code:
$1 ~ /^foo$/ && $2 ~ /^bar$/ Check out http://www.vectorsite.net/tsawk2.html#m3. That should help you. |
|
|||
|
Quote:
Quote:
Quote:
|
|
|||
|
thanks for your replies
but there is one more thing that i want to ask eval $(nawk -v out='testfileoutput -v counter1="${counter1}" -v counter2="${counter2}" ' why i cannot use the above line as follows: eval $(nawk '-v out=testfileoutput -v counter1="${counter1}" -v counter2="${counter2}" ' i moved the first single quote to just after nawk, before -v |
| Sponsored Links |
|
|
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Compound command with 'find' utility? | deckard | Shell Programming and Scripting | 6 | 10-05-2005 05:27 PM |
| Compound indirect variable references | tkrussel | UNIX for Advanced & Expert Users | 5 | 08-21-2005 11:03 AM |
| Trying to use 'compound variable' in a script | irina | Shell Programming and Scripting | 1 | 01-29-2004 10:33 PM |
| Trying to use 'compound variable' in a script | neemic | Shell Programming and Scripting | 3 | 01-16-2004 07:07 AM |
| compound expression in unix | spalmer | UNIX for Dummies Questions & Answers | 3 | 10-19-2001 01:04 PM |