Are you aware that. The next statement forces awk to immediately stop processing the current. if the next statement is used in a BEGIN or END rule. gawk treats it as a syntax error. Linux Awk Tutorials - Conditional If Else Statement Examples. Most of the Awk conditional statement syntax are looks like ' C' programming language. Could you help me with the following syntax error? i suppose you bash is sh: $ sh $ for( ( i= 2; i< 5; i+ + ) ) ; do echo $ i ; done sh: 1: Syntax error: Bad for loop variable. while it should be bash. I don' t think the error has anything to with your Awk command. I think you are running it in the POSIX bourne shell sh in which for- loop construct. You' ve got a condition, but no action in your awk program.
Try this: awk ' { if( FNR> = ENVIRON[ " lineNUM" ] & & FNR< = ENVIRON[ " next" ] ) print $ 0} '. I am very new to AWK although I have previously used the command prompt/ terminal. I have this script below where I am creating subsets of. As it is written in your question, the second parameter is an invalid string so awk complains and quit. The corrected awk statement is removing. The if - else statement is awk ' s decision- making statement. If you forget the ` ; ', awk won' t be able to interpret the statement, and you will get a syntax error.