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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:23:45+00:00 2026-05-27T03:23:45+00:00

how to match PARAM (param=name) word in file.txt and print the lines between NAMEx

  • 0

how to match PARAM (param=name) word in file.txt and print the lines between

NAMEx and NAMEy, via awk , as the following way :

if PARAM matched in the file.txt , then awk will print only the words between the close NAMES strings while PARAM is one of the names

remark1 PARAM can be any name as Pitter , Bob , etc…..

remark2 awk will get PARAM=(any name)

remark3 we not know how many spaces we have between (# to NAME)

 more file.txt

 #     NAMES1

   Pitter 23
   Bob 75 

 #  NAMES2

   Donald 54
   Josef 85
   Patrick 21  

 #         NAMES3

   Tom 32
   Jennifer 85
   Svetlana 25

 # NAMES4

examples ( regarding file.txt contents )

 In case PARAM=pitter then awk will print the names to out.txt file 

 Pitter 23
 Bob 75 


 In case PARAM=Josef then awk will print the names to out.txt file 


 Donald 54
 Josef 85
 Patrick 21  


 In case PARAM=Jennifer  then awk will print the names to out.txt file 


 Tom 32
 Jennifer 85
 Svetlana 25
  • 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-05-27T03:23:45+00:00Added an answer on May 27, 2026 at 3:23 am

    using RS of awk would be helpful in this case. see the test below:

    testing with example

    kent$  cat file
    # NAMES1
    
    Pitter 23
    Bob 75 
    
    # NAMES2
    
    Donald 54
    Josef 85
    Patrick 21  
    
    # NAMES3
    
    Tom 32
    Jennifer 85
    Svetlana 25
    
    # NAMES4
    
    kent$  awk -vPARAM="Pitter" 'BEGIN{RS="# NAMES."} {if($0~PARAM)print}' file               
    
    
    Pitter 23
    Bob 75 
    
    kent$  awk -vPARAM="Josef" 'BEGIN{RS="# NAMES."} {if($0~PARAM)print}' file                
    
    
    Donald 54
    Josef 85
    Patrick 21  
    
    kent$  awk -vPARAM="Jennifer" 'BEGIN{RS="# NAMES."} {if($0~PARAM)print}' file             
    
    
    Tom 32
    Jennifer 85
    Svetlana 25
    

    note, there are some empty lines in output, because they existed in your input. however it would be easy to remove them from output.

    update

    if you have spaces between # and NAMES, you can try:

    awk -vPARAM="Pitter" 'BEGIN{RS="# *NAMES."} {if($0~PARAM)print}' file 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What will be xpath expression to match the context-param with param-name foo as shown
I want match spaces at the beginning of lines in Vim PseudoCode of what
How do I match something thats A known part (unknown word) (the rest of
I'm trying to match the following items in the string pcode : u followed
I'm using the following rule in jquery validate to make a name field, called
I've come across the following snippet in an XSL file that I'm working with.
I have got this in my routes file: resources :users match '/@:id' => 'users#show'
I have an xsl:param that I'm trying to use to do a template match
match.matches() returns false. This is odd, because if I take this regex and test
preg_match() gives one match. preg_match_all() returns all matches. preg_split() returns all splits. How can

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.