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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:47:28+00:00 2026-06-06T19:47:28+00:00

Trying to get a bit more out of the command line: I have a

  • 0

Trying to get a bit more out of the command line:

I have a file:

CHR25   1192279 Y       Exonic  NA      exon    2       [1/1]   1192145 1192322
CHR25   1192279 Y       Exonic  NA      CDS     2       [1/1]   1192145 1192322  
CHR25   1739394 Y       Exonic  NA      CDS     2       [1/2]   1739294 1739456

I want to get unique lines based on column 2. I have done

cat file | cut -f 2 | uniq > grepfile

but am unsure of how to now get one match per line using grep -f as I previously have. Using -m1 or | head -n 1 only gives the first matching line. I want the first line to match each line in ‘grepfile’.

Look forward to answers=)

  • 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-06T19:47:31+00:00Added an answer on June 6, 2026 at 7:47 pm

    This awk command works by building an associative array of second-field values that have been seen already.

    awk '!s[$2]++'
    

    The associative array is called s. The expression looks up $2 (the second column of the input line) and applies a postincrement, which will return 0 the first time it’s called and nonzero thereafter. Then I invert it, yield 1 the first time each $2 is seen, and 0 every time afterward. And awk’s default action is to print if the selecting expression is true.

    Just watch out when the line count is big enough to wrap around to 0 again.

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

Sidebar

Related Questions

I'm trying to get a bit more functionality out my application. atm I have
I am trying to get this bit of JavaScript to run. I keep getting
I am trying to get git diff to work on Windows 7 64 bit.
I am just trying to get Hadoop running on my laptop running 64-bit Windows
I'm trying to get the pixel rgb values from a 64 x 48 bit
I am a bit puzzled with my Regex results (and still trying to get
I am trying to get information about a movie (resolution, frame rate, bit rate,
I am having a bit of a problem, I am trying to get a
I am having a little bit of trouble... I am trying to get a
struggling a bit to get the following to work : I'm trying to merge

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.