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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T14:33:34+00:00 2026-05-21T14:33:34+00:00

I have a text file with the following structure: text1;text2;text3;text4 … I need to

  • 0

I have a text file with the following structure:

text1;text2;text3;text4
...

I need to write a script that gets 2 arguments: the column we want to search in and the content we want to find.

So the script should output only the lines (WHOLE LINES!) that match content(arg2) found in column x(arg1).

I tried with egrep and sed, but I’m not experienced enough to finish it. I would appreciate some guidance…

  • 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-21T14:33:35+00:00Added an answer on May 21, 2026 at 2:33 pm

    Given your added information of needing to output the entire line, awk is easiest:

    awk -F';' -v col=$col -v pat="$val" '$col ~ pat' $input
    

    Explaining the above, the -v options set awk variables without needing to worry about quoting issues in the body of the awk script. Pre-POSIX versions of awk won’t understand the -v option, but will recognize the variable assignment without it. The -F option sets the field separator. In the body, we are using a pattern with the default action (which is print); the pattern uses the variables we set with -v for both the column ($ there is awk‘s “field index” operator, not a shell variable) and the pattern (and pat can indeed hold an awk-style regex).

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

Sidebar

Related Questions

Hi there I have to read data from text file into the array in
Having the following hierarchical text data input (JunOS-like, in fact) I need to parse
I have transformed one XML file to an another XML file (in desired structure)
Hey all i have code to write to an xml doc from asp string
Based on my settings, Paypal returns the following sample response: http://www.mydomain.com/some-seo-text-buy-callback.html?token=EC-80997676W8765&PayerID=KHDGEYEDJKD I want all
Ok, I have this php page that makes an searchItem request at amazon and
I am trying to use the ResourceBundle class to retrieve the locale specific text
I have a new django project called mysite. Inside mysite is a folder called
I know there are several similar questions, but I'm struggling to understand the error
I've become rather comfortable using RegEx in little javascript apps/plugins of mine but right

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.