Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Parsing two files, create a single uniq file

Status
Not open for further replies.

sumncguy

IS-IT--Management
May 22, 2006
118
US
I have two files.

Each file is an ascii file. They contain scripts that I and others have written over the years. I want to combined these two files and have a single uniq file.

Diff will show me all the differences, whats missing from one file or the other .. but how the heck can I keep the integrity ?


for instance

file 1 file 2 uniq file


script1 Ascript script1
bicycle red bicycle
car yellow car
boat blue boat

script2 script3 script2
motorcycle airplane motocycle
quad tricycle quad
skateboard skateboard
Bscript
script3 black script3
airplane green airplane
tricycle purple tricycle

Ascript
red
yellow
blue

Bscript
black
green
purple

No dupes, no loss, ....

Ive used prt -m to cat files with columns ... but not sure where to start here ..

Thanks
Chris
 
Hi

With [tt]grep[/tt] you can exclude those lines of one file which exist in the other. Then add concatenate the result with the other file. This preserves the original order.
Code:
grep -F -v -f "file 1" "file 2" | cat "file 1" - > "uniq file"

Feherke.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top