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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T02:29:49+00:00 2026-05-16T02:29:49+00:00

I have lines of data that contain single column and two columns. What I

  • 0

I have lines of data that contain
single column and two columns. What I want to do is to
extract lines that contain only 2 columns.

0333 foo
 bar
23243 qux

yielding only:

0333 foo
23243 qux

Note that they are tab separated, even for lines with only one column
you have tab at the beginning.

What’s the way to do it?

I tried this but fail:

awk '$1!="";{print $1 "\t" $2}' myfile.txt

enter code here
  • 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-16T02:29:50+00:00Added an answer on May 16, 2026 at 2:29 am

    You need to use the NF (number of fields) variable to control the actions, such as in the following transcript:

    $ echo '0333 foo
    >  bar
    > 23243 qux' | awk 'NF==2{print}{}'
    0333 foo
    23243 qux
    

    This will print the line if the number of fields is two, otherwise it will do nothing. The reason I have the (seemingly) strange construct NF==2{print}{} is because some implementations of awk will print by default if no rules are matched for a line. The empty command {} guarantees that this will not happen.

    If you’re lucky enough to have one of those that doesn’t do this, you can get away with:

    awk 'NF==2'
    

    but the first solution above will work in both cases.

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

Sidebar

Related Questions

I have a text box that contains lines of data similar to this: sheep
I have a data source with about 2000 lines that look like the following:
I have a program that reads data from a file line-by-line. I would like
I have a file which contains lines of data in the following format: a11
I have a tab-separated data file with a little over 2 million lines and
I would like to have a method along the lines of setData:(SomeClassName *)data inPosition:(NSInteger)position
I have a WinForms .NET datagrid whose data source is a List<cLineItem> called lines.
I have an XML file of this Kind : <data> <First id=FirstOne> <lines id=Lines>
I have two tables that need to be updated, Master and Identifiers: Master --MasterID
I have a text file that contains a data like ID Name Path IsTrue

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.