The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

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 10:47 AM
File Comparison net_shree Shell Programming and Scripting 19 01-10-2008 08:00 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 10-08-2008
satish.res satish.res is offline
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..
  #2 (permalink)  
Old 10-08-2008
jim mcnamara jim mcnamara is offline Forum Staff  
...@...
  
 

Join Date: Feb 2004
Location: NM
Posts: 5,710
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
  #3 (permalink)  
Old 10-08-2008
satish.res satish.res is offline
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..
  #4 (permalink)  
Old 10-08-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

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

Code:
awk>file3 'NR==FNR{_[$1];next}$1 in _' file1 file2
  #5 (permalink)  
Old 10-09-2008
satish.res satish.res is offline
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
  #6 (permalink)  
Old 10-09-2008
radoulov's Avatar
radoulov radoulov is offline Forum Staff  
addict
  
 

Join Date: Jan 2007
Location: Варна, България / Milano, Italia
Posts: 2,847
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
  #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
Sponsored Links
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 01:44 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
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