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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T11:49:36+00:00 2026-05-19T11:49:36+00:00

Working in linux/shell env, how can I accomplish the following: text file 1 contains:

  • 0

Working in linux/shell env, how can I accomplish the following:

text file 1 contains:

1
2
3
4
5

text file 2 contains:

6
7
1
2
3
4

I need to extract the entries in file 2 which are not in file 1. So ‘6’ and ‘7’ in this example.

How do I do this from the command line?

many thanks!

  • 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-19T11:49:36+00:00Added an answer on May 19, 2026 at 11:49 am
    $ awk 'FNR==NR {a[$0]++; next} !($0 in a)' file1 file2
    6
    7
    

    Explanation of how the code works:

    • If we’re working on file1, track each line of text we see.
    • If we’re working on file2, and have not seen the line text, then print it.

    Explanation of details:

    • FNR is the current file’s record number
    • NR is the current overall record number from all input files
    • FNR==NR is true only when we are reading file1
    • $0 is the current line of text
    • a[$0] is a hash with the key set to the current line of text
    • a[$0]++ tracks that we’ve seen the current line of text
    • !($0 in a) is true only when we have not seen the line text
    • Print the line of text if the above pattern returns true, this is the default awk behavior when no explicit action is given
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm working on Linux gcc environment and I need to initilize function arguments that
I am new to Linux shell and I found a way to get the
I am working on a linux daemon and having some issues with the stdin/stdout.
I am working on Linux and using a third party C, and bunch of
I have this file as: The number is %d0The number is %d1The number is
I'm working on Amazon's Elastic Map Reduce service and I want to bootstrap the
I am using mercurial as part of my workflow process and it is working
I'm running Ubuntu Linux with Eclipse installed, and I'm trying to work with JNI
I am debugging a program using gdb. Whenever I miss a breakpoint or decide
I know there are a lot of these topics around but none seem to

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.