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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T23:31:54+00:00 2026-06-07T23:31:54+00:00

I have a file which contains text and references to environment variables. Example: #PRINTME

  • 0

I have a file which contains text and references to environment variables. Example:

#PRINTME It is always fun to start your week on a sunny ${DAY_OF_WEEK}
#PRINTME My name is ${USERNAME}, you killed my father - prepare to die!
Unrelated gibberish - not to be printed
...

Think of it as metadata.

I want to define a command that greps this file and prints everything marked with #PRINTME and evaluates the environment variables as well.

I did this: grep #HELP myfile | sed "s/#PRINTME //g" | awk '{print $1}' but my output was

It is always fun to start your week on a sunny ${DAY_OF_WEEK}
My name is ${USERNAME}, you killed my father - prepare to die!

Instead of

It is always fun to start your week on a sunny Monday
My name is Inigo Montoya, you killed my father - prepare to die!

Is there a SHELL way to do what I want?
I’m using TCSH – can’t change that.
There are no issues with replacing grep, sed and awk.

  • 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-07T23:31:56+00:00Added an answer on June 7, 2026 at 11:31 pm

    You can do it with Gawk:

    gawk '
    
      /^#PRINTME/ {
    
        # Remove prefix
        sub( /^#PRINTME /, "" )
    
        # Loop while the line contains variables
        while( /\$\{[^}]+\}/ ) {
    
          # Extract the first variable name
          VAR = gensub( /^[^$]*\$\{([^}]+)\}.*$/, "\\1", 1 )
    
          # Replace it with its value
          gsub( "\\$\\{" VAR "\\}", ENVIRON[ VAR ] )
        }
    
        print
    
     }
    '
    

    The script find the variables one by one and replace them by their value.

    If you want the OS to evaluate the variables for you, it’s even easier (and doable in standard Awk):

    awk '/^#PRINTME/ { sub( /^#PRINTME /, "" ) ; system( "echo " $0 ) }'
    

    This time, we build an echo command and pass it to a shell.

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

Sidebar

Related Questions

I have a text file which contains data seperated by '|'. I need to
I have a text file which contains something like this: Hello, my name is
I have a simple text dictionary file, which contains words, separated by ';'.My problem
I have a text data file which contains text like this: [category.type.group.subgroup] - 2934:10,4388:20,3949:30
Problem I have a file which contains such text (nothing else) 2010-10-05 I would
I have a text file which contains data I need to preload into a
I have a file which contains several text entries, say one two three Now,
I have a text file which contains many (over 5000) links. Like this: http://www.website.com/rgfdefvrggh
I have a text file which contains content scraped from webpages. The text file
I am new to php. I have a text file which contains text something

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.