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
Extract all the content after a specific data patrick87 Shell Programming and Scripting 22 4 Weeks Ago 04:04 AM
find: No match due to find command being argument mst3k4l Shell Programming and Scripting 2 08-10-2009 10:48 AM
How to find first match and last match in a file praving5 Shell Programming and Scripting 3 04-01-2009 08:33 AM
X11 auth data does not match fake data samytrix UNIX for Dummies Questions & Answers 1 08-15-2008 04:32 PM
sed: find match and delete the line above cstovall Shell Programming and Scripting 3 07-02-2008 11:31 PM

Reply
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 128
what about join

Code:
join file1 file2

  #2 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 128
try this

Code:
cat file3 | tr "\n" "\t" > file4

or more direct

Code:
join FILE1.dat FILE2.dat | tr "\n" "\t" > file4


Last edited by frans; 4 Weeks Ago at 05:20 AM.. Reason: more direct
  #3 (permalink)  
Old 4 Weeks Ago
patrick87 patrick87 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 110
Hi,
I just try both of the code that you suggested.
End up It will link all the data together and generated the output like this:
1285_t chris germany 8288_c steve england 9626_a dave swiss
Do I did anything wrong?
Thanks again, frans
  #4 (permalink)  
Old 4 Weeks Ago
frans's Avatar
frans frans is online now
Registered User
  
 

Join Date: Oct 2009
Location: Drôme, France
Posts: 128
Quote:
Originally Posted by patrick87 View Post
Hi,
I just try both of the code that you suggested.
End up It will link all the data together and generated the output like this:
1285_t chris germany 8288_c steve england 9626_a dave swiss
Do I did anything wrong?
Thanks again, frans
You did allright
I think your awk script looks good. I couldn't do better
  #5 (permalink)  
Old 4 Weeks Ago
patrick87 patrick87 is offline
Registered User
  
 

Join Date: Sep 2009
Posts: 110
Never mind.
Knowledge is sharing ^^
  #6 (permalink)  
Old 4 Weeks Ago
panyam panyam is offline Forum Advisor  
Registered User
  
 

Join Date: Sep 2008
Posts: 474
Something like this :


Code:
awk 'NR==FNR{a[$1]=$1;next} { if($1 in a) print }' f1 f2

Not sure of the performance your expecting can be reached or not.
  #7 (permalink)  
Old 4 Weeks Ago
Scrutinizer Scrutinizer is offline
Registered User
  
 

Join Date: Nov 2008
Posts: 761
If it is too slow, you could test if awk runs faster. Especially mawk is lightning quick.

Code:
awk 'NR==FNR{a[$1]=1;next}a[$1]' file1 file2>file3



---------- Post updated at 03:37 AM ---------- Previous update was at 03:35 AM ----------

Oops somehow missed panyam's answer. Oh well..
Reply

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:28 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