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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T10:16:36+00:00 2026-06-13T10:16:36+00:00

I have a CSV file that look like this: A,B,C 1,2,3 4,4,4 1,2,6 3,6,9

  • 0

I have a CSV file that look like this:

A,B,C
1,2,3
4,4,4
1,2,6
3,6,9

Is there an easy way to grep all the rows in which the B column is 2, and keep the header? For example, I want the output be like

A,B,C
1,2,3
1,2,6

I am working under linux

  • 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-13T10:16:37+00:00Added an answer on June 13, 2026 at 10:16 am

    Using awk:

    awk -F, 'NR==1 || $2==2' file
    

    NR==1 -> if first line,
    $2==2 -> if second column is equal to 2. Lines are printed if either of the above is true.

    To choose the column using the header column name:

    awk -F, -v col="B" 'NR==1{for(i=1;i<=NF;i++)if($i==col)break;print;next}$i==2'  file
    

    Replace B with the appropriate name of the column which you want to check against.

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

Sidebar

Related Questions

I have about 20 CSV's that all look like this: [email],[fname],[lname],[prefix],[suffix],[fax],[phone],[business],[address1],[address2],[city],[state],[zip],[setdate],[email_type],[start_code] What I've been
I have a CSV file that goes something like this: ['Name1', '', '', '',
So I have file that with multiple line that look like this (space delimiter
So I have file with about thousand line that look like this: COADREAD ZNF271
I have a CSV file that is formatted like: 0.0023709,8.5752e-007,4.847e-008 and I would like
I have a CSV file that I'm working with, and all the fields are
Let's say we have a comma separated file (csv) like this: name of movie,starring,director,release
I have a csv file that has rows that I want to split by
I have big .csv file. I would like to filter that file into a
I have a CSV (comma separated values) file that contains student information. The column

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.