LinuxQuestions.org
Help answer threads with 0 replies.
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 10-12-2012, 10:56 AM   #1
arn2025
LQ Newbie
 
Registered: Feb 2012
Posts: 26
Blog Entries: 1

Rep: Reputation: Disabled
file compare and result output


hello;

i have two files 100kactivesept.csv and 100kactivevms.csv the two files are really long, however i want to spit out both results of field1 in file1 that are not in field 2 of file 2, and the vice versa, field 2 in file1 not in field one in file 1. hope am making sense.
Quote:
$ head 100kactivesept.csv
012071967934,100000
000029600012,100000
012071963923,100000
012071940886,100000
000029614463,100000
374745625,100000
374748422,100000
012071956396,100000
000029613510,100000
012071967627,100000
Quote:
/cygdrive/e/voucher/September
$ head 100kactivevms.csv
AT100K|247131123|
AT100K|247130535|
AT100K|247130418|
AT100K|247130988|
AT100K|247130550|
AT100K|247130997|
AT100K|247130157|
AT100K|247131072|
AT100K|247131081|
AT100K|247130601|
 
Old 10-12-2012, 11:43 AM   #2
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
As far as I could understand your requirement, if you want only 2nd field of first file and 1st field of second file, then do as:
1st file:
% more <filename> | awk -F"," '{print $2}' > /tmp/firstfile.txt
and for 2nd file:
% more <filename> | awk -F"|" '{print $1}' > /tmp/secondfile.txt
Then you'll get your desired output in /tmp/firstfile.txt and /tmp/secondfile.txt.
Moreover if you want to merge output of both /tmp/firstfile.txt and /tmp/secondfile.txt in columned manner, use following cmd:
% paste /tmp/firstfile.txt /tmp/secondfile.txt

Hope it will help you, else explain your question little more.
 
Old 10-12-2012, 12:34 PM   #3
arn2025
LQ Newbie
 
Registered: Feb 2012
Posts: 26
Blog Entries: 1

Original Poster
Rep: Reputation: Disabled
THIS DOES NOT GIVE THE DESIRED OUTPUT, I WOULD Like to get field ones that are not in field to of file 1, sort of like a vlookup
 
Old 10-12-2012, 12:53 PM   #4
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,027

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
^ what have you tried so far... i think awk, grep, sed, cut, ... would be useful in this exercise.

i would change one of the files so that the fields match and run grep -f -v in a while loop.

Last edited by schneidz; 10-12-2012 at 12:58 PM.
 
Old 10-12-2012, 02:00 PM   #5
shivaa
Senior Member
 
Registered: Jul 2012
Location: Grenoble, Fr.
Distribution: Sun Solaris, RHEL, Ubuntu, Debian 6.0
Posts: 1,800
Blog Entries: 4

Rep: Reputation: 286Reputation: 286Reputation: 286
Quote:
Originally Posted by arn2025 View Post
THIS DOES NOT GIVE THE DESIRED OUTPUT, I WOULD Like to get field ones that are not in field to of file 1, sort of like a vlookup
To be honest, your question is not so clear that what exactly you want. Better explain with some example and elaborate.
 
Old 10-12-2012, 05:12 PM   #6
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,396
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
Yes, please give examples and written explanation of how some parts of each file match. In the sample you provide, I can see almost no matching strings. For the sake of optimization, it would be useful to know a few more things:
  • are the records in each file ordered/sorted in any way?
  • are the records in each file unique (can a record in either be duplicated)?
  • is the order of the output records significant?
  • is there any positional correspondence between the records? i.e. does record #1 correspond to record #1 in each file?
That last one points to the possibility of some very lengthy searches. It may be necessary to scan each record of each file for every record of the other file, or even twice if you need to do the reverse comparison.
Your second sample file doesn't really look like a CSV formatted file. Are we to assume what the field delimiters are?

--- rod.

Last edited by theNbomr; 10-12-2012 at 05:14 PM.
 
  


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
[SOLVED] Compare two fields, then sort based on result. C.L. Programming 7 09-28-2010 10:43 AM
Clean Up Log - Search for Pattern in Log file and Output result bridrod Linux - Newbie 10 01-05-2010 10:49 AM
[SOLVED] Trying to compare two files and output it into a third file. chutsu Programming 11 07-31-2009 07:55 PM
compare the hostnames in /etc/hosts with the result of nslookup on a ip from /etc/hos pete83 AIX 3 12-18-2007 04:34 AM
Output the result of a command to a file darkarcon2015 Linux - Newbie 1 09-24-2005 07:29 PM


All times are GMT -5. The time now is 02:35 AM.

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
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration