![]() |
|
|
|
|
|||||||
| 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 |
| awk Shell Script error : "Syntax Error : `Split' unexpected | Herry | UNIX for Dummies Questions & Answers | 2 | 03-17-2008 08:16 AM |
| awk syntax error | orahi001 | UNIX for Dummies Questions & Answers | 0 | 03-17-2008 06:35 AM |
| syntax error | bkan77 | Shell Programming and Scripting | 2 | 07-30-2007 01:26 PM |
| I got error like...syntax error on line 1, teletype | koti_rama | UNIX for Advanced & Expert Users | 2 | 07-07-2007 04:35 PM |
| Syntax error.. | livetaurean19 | Shell Programming and Scripting | 0 | 06-14-2005 01:23 PM |
|
|
Submit Tools | LinkBack | Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
|
awk syntax error
Code:
mVar=0
count=`awk -F, '( ( $2 ~ /^GIVEUP$/ && $3 ~ /^NEW$/ ) || ( $2 ~ /^SPLIT$/ && $3 ~ /^NEW$/ ) || ( $2 ~ /^OPTION$/ && $3 ~ /^NEW$/ ) || ( $2 ~ /^OPTIONSPLIT$/ && $3 ~ /^NEW$/ ) ) { count++ } END { print count }' myCSV.csv
myVar=`expr $myVar + $count`
It works if I remove the 2nd two pairs of "or" operators. |
| Forum Sponsor | ||
|
|
|
#2
|
|||
|
|||
|
I didn't find the patience to count all the different types of brackets (I presume a miscount of them is causing the error), but even if the statement would work it would be pretty bad style (read: nearly unreadable for anybody else) so take the malfunction as a stroke of luck.
It is far easier to read to do something (only the skeleton) like: Code:
BEGIN {
count=0;
}
{
if( $2 ~ /^GIVEUP$/ && $3 ~ /^NEW$/ )
count ++;
if( $2 ~ /^SPLIT$/ && $3 ~ /^NEW$/ )
count ++;
if( ....
}
END {
print count;
}
bakunin |
|
#3
|
||||
|
||||
|
The OP's obfuscated code works fine for me (GNU awk).... my hunch is the omission of the closing backtick.....
Cheers ZB |
|
#4
|
||||
|
||||
|
Code can be simplified...
Code:
count=$(awk -F, '$2 ~ /^(GIVEUP|SPLIT|OPTION|OPTIONSPLIT)$/ && $3 == "NEW" { count++ }
END { print count }' myCSV.csv)
|
|
#5
|
|||
|
|||
|
very appreciative
ah, thanks guys.
i'm always interested in writing better, easier to understand code, and this post definitely helped out in that department Last edited by yongho; 06-20-2005 at 07:19 AM. |
|||
| Google The UNIX and Linux Forums |