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 > UNIX for Dummies Questions & Answers
.
google unix.com



UNIX for Dummies Questions & Answers If you're not sure where to post a UNIX or Linux question, post it here. All UNIX and Linux newbies welcome !!

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
how can i add two numbers kripssmart UNIX for Dummies Questions & Answers 4 01-06-2009 06:45 PM
Numbers of records in SAS dataset sasaliasim Shell Programming and Scripting 2 04-21-2008 04:55 PM
need top 3 numbers shary Shell Programming and Scripting 4 03-25-2008 01:58 AM
How to add numbers? pnxi Shell Programming and Scripting 7 09-11-2003 06:25 AM
Add some numbers! TalkShowHost Shell Programming and Scripting 3 05-15-2002 12:28 PM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 11-25-2008
Shiv@jad Shiv@jad is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 27
seperating records with numbers from a set of numbers

I have two files one (numbers file)contains the numbers(approximately 30000) and the other file(record file) contains the records(approximately 40000)which may or may not contain the numbers from that file.

I want to seperate the records which has the field 1=(any of the number from numbers file). Can you please suggest how it can be achieved without having performance issues.


Regards
Shiv@jad
  #2 (permalink)  
Old 11-25-2008
mk1216 mk1216 is offline
Registered User
  
 

Join Date: Sep 2008
Location: Bristol , United Kingdom
Posts: 38
Can you post sample data from both the files , we can try something using AWKand FOR loop.
  #3 (permalink)  
Old 11-25-2008
Shiv@jad Shiv@jad is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 27
The sample numbers are
027245799
010479168
015286940
043385828
and sample recors are nothing but the records with comma seperated fields wherein we have to search these numbers in first comma seperated field
  #4 (permalink)  
Old 11-25-2008
mk1216 mk1216 is offline
Registered User
  
 

Join Date: Sep 2008
Location: Bristol , United Kingdom
Posts: 38
$> cat data.dat
1,3,4,
m,h,j
4,5,h
h,t,y
r,t,b
3,f,r

$> cat numbers.dat
1
2
3
4
5


for i in `cat numbers.dat`
do
cat data.dat|awk -F"," '{if($1==number) print $0}' number="$i"
done

OUTPUT
1,3,4,
3,f,r
4,5,h
  #5 (permalink)  
Old 11-25-2008
mk1216 mk1216 is offline
Registered User
  
 

Join Date: Sep 2008
Location: Bristol , United Kingdom
Posts: 38
"number" is a variable in AWK which is initialised to shell variable "i" .
  #6 (permalink)  
Old 11-25-2008
Shiv@jad Shiv@jad is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 27
Thanks a lot this is what i needed will try this code block
  #7 (permalink)  
Old 11-25-2008
Shiv@jad Shiv@jad is offline
Registered User
  
 

Join Date: Nov 2006
Posts: 27
Can you please let me know how can i redirect it to some different file.
Sponsored Links
Closed Thread

Bookmarks

Tags
shell script, shell scripting, unix scripting, unix scripting basics

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 12:44 PM.


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