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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T20:48:16+00:00 2026-06-16T20:48:16+00:00

I would like to have a shell script that searches two files and returns

  • 0

I would like to have a shell script that searches two files and returns a list of strings:

File A contains just a list of unique alphanumeric strings, one per line, like this:

accc_34343
GH_HF_223232
cwww_34343
jej_222

File B contains a list of SOME of those strings (some times more than once), and a second column of infomation, like this:

accc_34343 dog
accc_34343 cat
jej_222 cat
jej_222 horse

I would like to create a third file that contains a list of the strings from File A that are NOT in File B.

I’ve tried using some loops with grep -v, but that doesn’t work. So, in the above example, the new file would have this as it’s contents:

GH_HF_223232
cwww_34343

Any help is greatly appreciated!

  • 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-16T20:48:17+00:00Added an answer on June 16, 2026 at 8:48 pm

    Here’s what you can do:

    grep -v -f <(awk '{print $1}' file_b) file_a > file_c
    

    Explanation:

    • grep -v : Use -v option to grep to invert the matching
    • -f : Use -f option to grep to specify that the patterns are from file
    • <(awk '{print $1}' file_b): The <(awk '{print $1}' file_b) is to simply extract the first column values from file_b without using a temp file; the <( ... ) syntax is process substitution.
    • file_a : Tell grep that the file to be searched is file_a
    • > file_c : Output to be written to file_c
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like to have a shell script that copies some logs from a
I have a shell script that I would like to test with shUnit. The
I have a shell script that I would like to run at the end
I have a Korn shell script that I would like to change a variable
I would like to introduce multithreading feature in my shell script. I have a
I have found a useful shell script that shows all files in a directory
I have created a shell .command on Mac OS X that I would like
I have an application that I'm creating and would like to run a shell
I have a Bash shell script that invokes a number of commands. I would
I have a shell script that calls a java jar file and runs an

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.