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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T22:57:02+00:00 2026-06-12T22:57:02+00:00

I have this file myfile a b c d e 1 b c s

  • 0

I have this file

myfile

a b c d e 1  
b c s d e 1  
a b d e f 2  
d f g h j 2  
awk 'if $6==$variable {print @0}' myfile

How can I use this code in shell script that get $variable as parameter by user in command prompt?

  • 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-12T22:57:03+00:00Added an answer on June 12, 2026 at 10:57 pm

    You can use awk‘s -v flag. And since awk prints by default, you can try for example:

    variable=1
    awk -v var=$variable '$6 == var' file.txt
    

    Results:

    a b c d e 1
    b c s d e 1
    

    EDIT:

    The command is essentially the same, wrapped up in shell. You can use it in a shell script with multiple arguments like this script.sh 2 j

    Contents of script.sh:

    command=$(awk -v var_one=$1 -v var_two=$2 '$6 == var_one && $5 == var_two' file.txt)
    echo -e "$command"
    

    Results:

    d f g h j 2
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Let's say I have this file on my server: server/myFile.txt How can I make
Say you have a file myfile.php which executes some PHP code. Could this file
I have this simple code inserted in myfile.hpp file inside a project of mine:
I have an NSURL that looks like this: file://localhost/Users/myuser/myfile.txt Is there a standard function
I have this code that deletes a specific file under a folder that I've
I have created a file named MyFile.db using SQLite3 from my C#.net application. This
I have a file as documentRoot/app/webroot/myFile.php I need to be able to access this
I have a file named my file.pdf and I can't delete this file with
Is there a way to have something like this: File.new('http://hostname/myfile.zip') inside a controller?
I have a generated txt file. This file has certain lines that are superfluous,

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.