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 8482797
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:54:29+00:00 2026-06-10T19:54:29+00:00

I want handle strings of the form: PREFIX_TYPE_N,DATA So, does the *awk (gawk, mawk,

  • 0

I want handle strings of the form:

PREFIX_TYPE_N,DATA

So, does the *awk (gawk, mawk, nawk) support including pattern matching in the action for already matched string? Something like this (of course, doesn’t work for me):

*awk 'BEGIN { FS="," }
     /PREFIX/ {
                /TYPE_1/  {printf "[TYPE1] [DATA: $2]"}    // <-- included pattern 
                /TYPE_2/  {printf "[TYPE2] [DATA: $2]"}    // <-- another included pattern
                ...                                        // <-- some more included patterns
              }' "filename"

Or do I still need if/else or switch/case?

  • 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-10T19:54:30+00:00Added an answer on June 10, 2026 at 7:54 pm

    Not quite in that way, but pretty close, as there is a regular expression match operator (~):

    BEGIN { FS="," }
    /PREFIX/ {
                if ($1 ~ "TYPE_1") {printf "[TYPE1] [DATA: $2]"}    // <-- included pattern 
                if ($1 ~ "TYPE_2") {printf "[TYPE2] [DATA: $2]"}    // <-- another included pattern
                ...                                        // <-- some more included patterns
              }
    

    Note that because the first pattern match will already enter its block with only one row processed, it’s fine to have only ifs in the block.

    If you really want the legibility of patterns, you could do this:

    BEGIN { FS="," }
    /PREFIX/ { //stuff to do for all prefixes, before specific handling
              data = $2 }
    /PREFIX_TYPE_1/ { type = "TYPE_1"; }
    /PREFIX_TYPE_2/ { type = "TYPE_2"; }
    /PREFIX/ { //stuff to do for all prefixes, after specific handling 
              printf("[%s] [DATA: $2]", type, data)
              }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to take HTML form data and handle the submited data(string for example)
I want to handle mouse click in a native MFC application from a C#
I want to handle the focus out Handler only to the component which i
I want to handle the keydown event globally in my application and as such
I want to handle events on a treeview with ACB ( http://marlongrech.wordpress.com/2008/12/04/attachedcommandbehavior-aka-acb/ ). I
i want to handle the tab keypress in such a way that if there
I have an input box which I want to handle two types of information,
I have an ATL app where I want to handle WM_POWERBROADCAST . I have
So I want to have tabs with default style but I want to handle
I have a frame extends from JWindow (because I want to handle my X

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.