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

  • SEARCH
  • Home
  • 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 8242979
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T21:21:09+00:00 2026-06-07T21:21:09+00:00

This is such a basic question in awk . But I am facing issues

  • 0

This is such a basic question in awk . But I am facing issues in this and I dont know why. problem is when I run the awk command in a single line such as

awk 'BEGIN {} {print $0;}' FILE 

Then the code is running perfecctly

But if I split the code between lines such as

 awk '
 BEGIN
 {
 }
 {
      print $0;
 }' FILE

It gives me an error stating that BEGIN should have an action part . I was wondering since it is the same code that I am formatting, why am I getting this error. Its really important for me to solve this as I would be writting large lines of codes in awk it would be difficult for me to format and bring it in a single line everytime. Could you ppl please help me regarding this. Thank you. Note. I am running this awk in shell environment

  • 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-07T21:21:11+00:00Added an answer on June 7, 2026 at 9:21 pm

    Add the '{' right after theBEGIN` and you will not get the error message.

    The opening paren { for BEGIN needs to be on the same line as BEGIN. So change what you have

    awk '
     BEGIN
     {
    

    to

    awk '
     BEGIN {
    

    and you won’t get the error message.

    The manual does state that “BEGIN and END rules must have actions;”, so that may be another problem. This

    awk 'BEGIN {} ...
    

    seems a bit odd to me (and there’s really no reason to have this if nothing is happening)

    @Birei’s helpful comment below explains that the way these statements will “parse will be different in both cases. The open '{' in next line is parsed as an action without pattern (not related with BEGIN), while in same line means an empty action of the BEGIN rule.”

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

Sidebar

Related Questions

This is such a basic question but for some reason all my knowledge of
Sorry for such a basic question regarding lists, but do we have this feature
Sorry this is such a basic question, but I can't find a straight answer
This is such a basic question, but I have to ask. In SL, I
Apologies for such a basic question but I can't figure it out. I know
This is such a simple problem, but I can't find an answer anywhere... I
sorry this is such a simple question but I can't figure it out. How
I know this question has been discussed before, and I know this is such
this must be such a simple problem but can someone tell me why this
This seems like such a basic question, so I apologize if it's already been

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.