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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T14:00:01+00:00 2026-06-04T14:00:01+00:00

I am comparing two files, each having one column and n number of rows.

  • 0

I am comparing two files, each having one column and n number of rows.

file 1

vincy
alex
robin

file 2

Allen
Alex
Aaron
ralph
robin

if the data of file 1 is present in file 2 it should return 1 or else 0, in a tab seprated file.

Something like this

vincy 0
alex 1
robin 1

What I am doing is

#!/bin/bash
for i in `cat file1 `
do
cat file2 | awk '{ if ($1=="'$i'") print 1 ; else print 0 }'>>binary
done

the above code is not giving me the output which I am looking for.

Kindly have a look and suggest correction.

Thank you

  • 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-04T14:00:04+00:00Added an answer on June 4, 2026 at 2:00 pm

    The following code should do it.

    Take a close look to the BEGIN and END sections.

    #!/bin/bash
    rm -f binary
    for i in $(cat file1); do
         awk 'BEGIN {isthere=0;} { if ($1=="'$i'") isthere=1;} END { print "'$i'",isthere}' < file2 >> binary
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have 8 files of one column and non uniform number of rows in
I am comparing between two tables first column each. If there is find a
i have two text files file 1 number,name,account id,vv,sfee,dac acc,TDID 7000,john,2,0,0,1,6 7001,elen,2,0,0,1,7 7002,sami,2,0,0,1,6 7003,mike,1,0,0,2,1
I have two .csv files containing correlation matrices exported from R. One file contains
in my application i am comparing two docx files and creating one html comparison
I am comparing the date when a file was last modified for two files,
Using Windows XP, I created a batch-file that takes two files as arguments, and
I need help with comparing two files in makefile. I need something like this:
I'm comparing two examples of WCF. Microsoft's examples http://msdn.microsoft.com/en-us/library/ms734712.aspx uses app.config file, uses generator
I am coding a class that compares the files of two directories via comparing

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.