The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > Shell Programming and Scripting
.
google unix.com



Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
File structure comparison krishmaths Shell Programming and Scripting 3 07-07-2008 01:16 PM
file comparison...help needed. er_ashu UNIX for Dummies Questions & Answers 4 05-15-2008 09:37 PM
Output format - comparison with I/p file velappangs Shell Programming and Scripting 1 04-03-2008 06:31 AM
file comparison script tiger99 Shell Programming and Scripting 1 01-30-2008 09:47 AM
File Comparison net_shree Shell Programming and Scripting 19 01-10-2008 07:00 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Question file comparison

hi

I have 2 files to comapre ,in file a sible column it is numbers,in file b2 numbers and other values with coma separated.
i want compare numbers in file a with file b,and the out put put should be in C with numbers in both file a and b along with other columns of file b.

i used folowing scripts
for line in `cat gprs2.txt`
do
more gprs_calls2.txt |grep $line >> NEW2.txt
done
exit

but it is not giving correct out put.and also this scrpits is not sppedy

plz help..
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 10-08-2008
...@...
 

Join Date: Feb 2004
Location: NM
Posts: 5,214
start with something like this:
Code:
grep -f gprs2.txt  gprs_calls2.txt > NEW2.txt
I had trouble understanding what you need. This just prints what is in file gprs_calls2.txt. Not what is in both files
Reply With Quote
  #3 (permalink)  
Old 10-08-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
The files are like this

File1
12345
56789
23456

File2
12345 fsfsdf 76775
23456 ytyy 090890
66444 rytry 878878

The out put should be
12345 fsfsdf 76775
23456 ytyy 090890

The file1 contains arround 1 million lines file2 has 2.5 million lines

pls help..
Reply With Quote
  #4 (permalink)  
Old 10-08-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,453
The standard solution will hold the entire file1 in memory:

Code:
awk>file3 'NR==FNR{_[$1];next}$1 in _' file1 file2
Reply With Quote
  #5 (permalink)  
Old 10-09-2008
Registered User
 

Join Date: Oct 2008
Posts: 7
Question

I have Tried .could u plz help..
out 'NR==FNR{_[$1];next}$1 in _' gprs2.txt gprs_calls2.txt

scripts by rplacing the respective filenames ,the out put does not have any data
the actual file lokks like this
Source file
7055000601
7055000633
7055000965
7055001182
7055001352
7055001468

Dest file to be compared(Source file no should be compared with dest file,the out should be the no of desti ,which exists in source,along with othere columns of desti corresponds the number
7055000601,35250401506992,621505200525591
7055000633,35574402566128,621505200525623
7055000965,35966800701265,621505200525952
7055001182,35844301188404,621505200526156
7055001352,35350902954276,621505200526325
7055001468,35195101170824,621505200526441
7055001490,35501600003290,621505200526463
7055003310,35487502010707,621505200528256
7055006309,04857558566586,621505200531213
Reply With Quote
  #6 (permalink)  
Old 10-09-2008
radoulov's Avatar
addict
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,453
Yes,
that's because the sample data you provided had a different format.

You may try this:

(use nawk or /usr/xpg4/bin/awk on Solaris)

Code:
awk>file3 'NR==FNR{_[$1];next}$1 in _' file1 FS=, file2
Reply With Quote
  #7 (permalink)  
Old 10-09-2008
era era is offline Forum Advisor  
Herder of Useless Cats (On Sabbatical)
 

Join Date: Mar 2008
Location: /there/is/only/bin/sh
Posts: 3,652
The field separator is missing from radoulov's script.

Code:
awk -F, 'NR==FNR{_[$1];next}$1 in _' gprs2.txt gprs_calls2.txt
Your description of the output you require is not understandable to me. This will print the lines in gprs_calls2.txt whose first field matches a value in (the first field of) gprs2.txt.

Last edited by era; 10-09-2008 at 06:25 AM.. Reason: I mean the earlier version of radoulov's script -- we posted basically at the same time
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 08:41 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66