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
Comparing two files superstar003 Shell Programming and Scripting 2 05-08-2008 04:36 AM
comparing shadow files with real files terrym UNIX for Advanced & Expert Users 4 02-09-2007 02:38 AM
comparing two files using awk. jerome Sukumar Shell Programming and Scripting 4 11-22-2006 06:27 AM
comparing files to contents of a file SummitElse Shell Programming and Scripting 3 06-28-2006 12:36 PM
shell script comparing files in a file raina_nalin Shell Programming and Scripting 4 06-21-2005 06:00 AM

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 02-15-2008
manmohanpv manmohanpv is offline
Registered User
  
 

Join Date: Feb 2008
Posts: 1
Shell script for merging two files without duplicating the data

File 1 data:

TestA
TestB
TestC


File 2 data:

TestA
TestD
TestE


My Output File (pick all from both and create a file without duplicate data)
----------------------------------------------------------------------

TestA
TestB
TestC
TestD
TestE

----------------------------------------------------------------
here, TestA comes in both files, i dont want to duplicate it (appear multiple times) in my output file. How can i do it?

Thanks in advance,

-mac

Last edited by manmohanpv; 02-16-2008 at 04:46 AM..
  #2 (permalink)  
Old 02-16-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
Code:
awk '!x[$0]++' file1 file2
  #3 (permalink)  
Old 02-16-2008
robotronic's Avatar
robotronic robotronic is offline Forum Advisor  
Can I play with madness?
  
 

Join Date: Apr 2002
Location: Italy
Posts: 370
I've misunderstood the request. The previous script removes duplicate entries but doesn't sort the data.

You can simply use:

Code:
sort -u file1 file2
  #4 (permalink)  
Old 02-18-2008
summer_cherry summer_cherry is offline Forum Advisor  
Registered User
  
 

Join Date: Jun 2007
Location: Beijing China
Posts: 1,078
sort+sed+comm

Hi,

Follow one should be ok for you.

Code:
sort file1 > t1
sort file2 > t2
comm t1 t2 | sed 's/	//g'
rm t1 t2
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 08:45 PM.


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