Unix administration - Merging two files

This is Interesting: Free IT Magazines  
Home > Archive > Unix administration > March 2007 > Merging two files





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Merging two files
Rafael Almeida

2007-03-11, 1:22 am

Hello,

Is there some tool like merge but for 2 files? I was trying to
work with merge, but I can't seem to get what I want. This is what I
get:
$ cat hosts
# $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
#
# Host Database
#
# RFC 1918 specifies that these networks are "internal".
# 10.0.0.0 10.255.255.255
# 172.16.0.0 172.31.255.255
# 192.168.0.0 192.168.255.255
#
::1 localhost.boozar.com localhost
127.0.0.1 localhost.boozar.com localhost
::1 blimp.boozar.com blimp
127.0.0.1 blimp.boozar.com blimp
$cat hosts2
# $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
#
# Host Database
#
# RFC 1918 specifies that these networks are "internal".
# 10.0.0.0 10.255.255.255
# 172.16.0.0 172.31.255.255
# 192.168.0.0 192.168.255.255
#
::1 localhost.my.domain localhost
127.0.0.1 localhost.my.domain localhost
::1 noname.my.domain noname
127.0.0.1 noname.my.domain noname
$ merge empty hosts hosts2
merge: warning: overlaps or other problems during merge
$ cat empty
<<<<<<< empty
=======
# $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
#
# Host Database
#
# RFC 1918 specifies that these networks are "internal".
# 10.0.0.0 10.255.255.255
# 172.16.0.0 172.31.255.255
# 192.168.0.0 192.168.255.255
#
::1 localhost.my.domain localhost
127.0.0.1 localhost.my.domain localhost
::1 noname.my.domain noname
127.0.0.1 noname.my.domain noname[vbcol=seagreen]

and this is what I expect the output to be:
# $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
#
# Host Database
#
# RFC 1918 specifies that these networks are "internal".
# 10.0.0.0 10.255.255.255
# 172.16.0.0 172.31.255.255
# 192.168.0.0 192.168.255.255
#
<<<<<<< hosts
::1 localhost.boozar.com localhost
127.0.0.1 localhost.boozar.com localhost
::1 blimp.boozar.com blimp
127.0.0.1 blimp.boozar.com blimp
=======
::1 localhost.my.domain localhost
127.0.0.1 localhost.my.domain localhost
::1 noname.my.domain noname
127.0.0.1 noname.my.domain noname[vbcol=seagreen]
Michael Tosch

2007-03-13, 7:17 pm

Rafael Almeida wrote:[vbcol=seagreen]
> Hello,
>
> Is there some tool like merge but for 2 files? I was trying to
> work with merge, but I can't seem to get what I want. This is what I
> get:
> $ cat hosts
> # $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
> #
> # Host Database
> #
> # RFC 1918 specifies that these networks are "internal".
> # 10.0.0.0 10.255.255.255
> # 172.16.0.0 172.31.255.255
> # 192.168.0.0 192.168.255.255
> #
> ::1 localhost.boozar.com localhost
> 127.0.0.1 localhost.boozar.com localhost
> ::1 blimp.boozar.com blimp
> 127.0.0.1 blimp.boozar.com blimp
> $cat hosts2
> # $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
> #
> # Host Database
> #
> # RFC 1918 specifies that these networks are "internal".
> # 10.0.0.0 10.255.255.255
> # 172.16.0.0 172.31.255.255
> # 192.168.0.0 192.168.255.255
> #
> ::1 localhost.my.domain localhost
> 127.0.0.1 localhost.my.domain localhost
> ::1 noname.my.domain noname
> 127.0.0.1 noname.my.domain noname
> $ merge empty hosts hosts2
> merge: warning: overlaps or other problems during merge
> $ cat empty
> <<<<<<< empty
> =======
> # $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
> #
> # Host Database
> #
> # RFC 1918 specifies that these networks are "internal".
> # 10.0.0.0 10.255.255.255
> # 172.16.0.0 172.31.255.255
> # 192.168.0.0 192.168.255.255
> #
> ::1 localhost.my.domain localhost
> 127.0.0.1 localhost.my.domain localhost
> ::1 noname.my.domain noname
> 127.0.0.1 noname.my.domain noname
>
> and this is what I expect the output to be:
> # $OpenBSD: hosts,v 1.11 2002/09/26 23:35:51 krw Exp $
> #
> # Host Database
> #
> # RFC 1918 specifies that these networks are "internal".
> # 10.0.0.0 10.255.255.255
> # 172.16.0.0 172.31.255.255
> # 192.168.0.0 192.168.255.255
> #
> <<<<<<< hosts
> ::1 localhost.boozar.com localhost
> 127.0.0.1 localhost.boozar.com localhost
> ::1 blimp.boozar.com blimp
> 127.0.0.1 blimp.boozar.com blimp
> =======
> ::1 localhost.my.domain localhost
> 127.0.0.1 localhost.my.domain localhost
> ::1 noname.my.domain noname
> 127.0.0.1 noname.my.domain noname

Sorry don't know about the merge command.

Perhaps you can cope with

awk 's[$0]++==0' hosts hosts2

which concatenates hosts and hosts2 but does not print
duplicate lines.
(It stores/compares all line in/with the s array.)

--
Michael Tosch @ hp : com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com