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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T21:44:35+00:00 2026-05-25T21:44:35+00:00

I am writing a shell script which needs to pull values out of a

  • 0

I am writing a shell script which needs to pull values out of a text file which looks like this:

app.full.name /warfilelocation/ warfilename

My shell script will be iterating over a list of application names and pulling out either the location or name using AWK. I have tested doing this on the command line using the following:
awk “\$1 ~/app.full.name/ { print $2 }” applications.txt

which returns what I would expect however when i put this in a shell script I start having issues.

I have a function that looks like this:

function get_location() {
        local application=$1
        awk "\$1 ~/^$application/ { print \$2 }"  applications.txt 
}

But when i call this function i get the following error:

awk: $1 ~/^app.full.name
awk:      ^ unterminated regexp
awk: cmd. line:1: app.full.name
awk: cmd. line:1:         ^ syntax error
awk: cmd. line:2: app.full.name/ { print $2 }
awk: cmd. line:2:    ^ syntax error

Does anyone have any ideas what I am doing wrong here. I presume I am not escaping the variable correct but no matter what i try it doesnt seem to work.

Thanks in advance

  • 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-25T21:44:36+00:00Added an answer on May 25, 2026 at 9:44 pm

    Use this approach to make awk recognize shell variables:

    awk -v "v1=$VAR1" -v "v2=$VAR2" '{print v1, v2}' input_file
    

    Update

    $ cat input
    tinky-winky
    dipsy
    laa-laa
    noo-noo
    po
    
    $ teletubby='po'
    
    $ awk -v "regexp=$teletubby" '$0 ~ regexp' input
    po
    

    Note that anything could go into the shell-variable,
    even a full-blown regexp, e.g ^d.*y. Just make sure to use single-quotes
    to prevent the shell from doing any expansion.

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

Sidebar

Related Questions

I'm writing a shell script to parse through log file and pull out all
I am writing a shell script that takes file paths as input. For this
I'm writing a shell script and I need to strip FIND ME out of
I am writing a shell (bash) script and I'm trying to figure out an
I'm writing a small shell script that needs to reverse the lines of a
I am writing a shell script (which I suck at) and I need some
I would like to real-hand experienced answer on this. Which one is faster? Writing
I am writing a simple shell script which changes the mac address of the
I'm writing a shell script which will rsync files from remote machines, some linux,
I'm writing a shell script which iterates over a set of variables, edits a

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.