Merging two files
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Unix support > Unix administration > Merging two files




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    Merging two files  
Rafael Almeida


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-11-07 07: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] 





[ Post a follow-up to this message ]



    Re: Merging two files  
Michael Tosch


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
03-14-07 12:17 AM

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





[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 04:29 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register