LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 11-09-2012, 12:50 AM   #1
Vthimmap
Member
 
Registered: Oct 2012
Posts: 36

Rep: Reputation: Disabled
compare first column of 2 files with awk


Need to compare first column of 2 files using awk
sample file1:
ECDLY 5
DBGO 0
ATDLM -10000
LDTHB 4
OMSTD 1

sample file2:
ECDLY 5
DBGBB 0
ATDLM -10000
LDTHB 4
OMSTD 1
AABLO 8
INDCL 4
 
Old 11-09-2012, 01:21 AM   #2
Vthimmap
Member
 
Registered: Oct 2012
Posts: 36

Original Poster
Rep: Reputation: Disabled
And i need the output in result.txt file
 
Old 11-09-2012, 01:30 AM   #3
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
A few questions:

- Does it have to be awk?
- What needs to go in results.txt? Entries present in both or those not in file1 or those not in file2?
- Should column 2 be included in results.txt?

Details please.
 
Old 11-09-2012, 01:34 AM   #4
Vthimmap
Member
 
Registered: Oct 2012
Posts: 36

Original Poster
Rep: Reputation: Disabled
Any command in unix is fine (other than awk )
result.txt - what is not present in file1 with respect to file 2

yes column 2 should be included.
 
Old 11-09-2012, 01:39 AM   #5
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403Reputation: 2403
Have a look at this:
Code:
comm -13 <(sort file1) <(sort file2) > results.txt
 
1 members found this post helpful.
Old 11-09-2012, 02:59 AM   #6
Vthimmap
Member
 
Registered: Oct 2012
Posts: 36

Original Poster
Rep: Reputation: Disabled
Hey this is really working .
Thanks a lot
cheers
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Please help compare 2 files via awk/sed Seemoi Programming 10 06-24-2012 01:23 PM
compare second column of a file then print the first column of it in a ne fil if true java_girl Linux - Newbie 2 03-16-2012 04:50 AM
compare two files using Awk!! visitnag Linux - Newbie 3 09-15-2008 12:42 PM
AWK: compare two files haydar68 Programming 6 08-02-2008 11:20 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:49 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration