Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8132707
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T09:24:35+00:00 2026-06-06T09:24:35+00:00

I am using if else statements in awk . Everytime when I use it

  • 0

I am using if else statements in awk. Everytime when I use it I am getting a syntax error. Could anyone tell me how to use this? I am getting syntax error shown below.

Code:

awk '{ FS = "=" ;if($1 ~ /Hi/) {if (!($1=="Hi")) {print $1;}} else {if($1=="bye") {print $1;}}} else {if(if($1=="good") {print $1;}}} END {print $1}'

Output:

awk: { FS = "=" ;if($1 ~ /Hi/) {if (!($1=="Hi")) {print $1;}} else {if($1=="bye") {print $1;}}} else {if(if($1=="good") {print $1;}}} END {print $1}

awk:                                                                                            ^ syntax error

awk: { FS = "=" ;if($1 ~ /Hi/) {if (!($1=="Hi")) {print $1;}} else {if($1=="bye") {print $1;}}} else {if(if($1=="good") {print $1;}}} END {print $1}

awk:                                                                                                     ^ syntax error

awk: { FS = "=" ;if($1 ~ /Hi/) {if (!($1=="Hi")) {print $1;}} else {if($1=="bye") {print $1;}}} else {if(if($1=="good") {print $1;}}} END {print $1}

awk:                                                                                                                                ^ syntax error
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T09:24:36+00:00Added an answer on June 6, 2026 at 9:24 am

    Problems

    There are a lot of things wrong with your code. You have unbalanced braces, poor spacing, and other issues that make debugging hard. Ultimately, you have syntax and quoting problems.

    Solutions

    You can simplify your code by moving the assignment to FS outside your script. This is much more readable and less error-prone. For example:

    $ echo "foo=bar" | awk -F= '{print $1}'
    foo
    

    You could also move your assignment to a BEGIN block for clarity, unless you are re-assigning it to something different at runtime.

    BEGIN { FS = "=" }
    

    No matter what else you do, if you refactor your code for readabilty, you will have a much easier time debugging your script.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im using the following JS <a href=# onClick=if($(this).next('div').css('display') == 'none') { $(this).next('div').show('fast'); } else
Are there any performance differences between using if-else and case statements when handling multiple
I am having problem using the if/then/else statements. here is my context: $email =
I am having to use if/else statements to output a currency value tied to
Is using 50 if-else statements too resource-intensive for one action? I'm doing something like
In MetaWhere I combined conditions to sql variable using loops, if else statements. sql
What solutions,patterns usually used for this? I want to get rid of if/else statements
The basis of the assignment is to use the if/else if statements to set
I am working on an Outlook add-in written by someone else using VSTO 4.0.
I am writing an if/else alternative using a table driven method. I have the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.