- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - Linux
- >
- How i can merge two text files?
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 09:08 AM
тАО09-06-2006 09:08 AM
i have two text files with table names,for example:
file1 file2
--------|-------------
tab1 tab6
tab2 tab2
tab3 tab5
tab4 tab7
tab5 | tab4
How i can merge file1 and file2 and produce file3 with all table names , with NO duplicate table names?
thanks
Best regards.
Francesco
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 09:27 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 09:31 AM
тАО09-06-2006 09:31 AM
Re: How i can merge two text files?
- Tags:
- Sort
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 09:33 AM
тАО09-06-2006 09:33 AM
Re: How i can merge two text files?
for the same table name in file1 and file2, i'm do it to write the table name from file2 only.(the duplicate table_name to eliminate it's the table_name from file1).
more thanks and regards
Francesco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 09:43 AM
тАО09-06-2006 09:43 AM
Re: How i can merge two text files?
You wrote, "for the same table name in file1 and file2, i'm do it to write the table name from file2 only.(the duplicate table_name to eliminate it's the table_name from file1).".
I'm missing something. What does it matter if they are the same?
Regards!
...JRF...
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:03 AM
тАО09-06-2006 10:03 AM
Re: How i can merge two text files?
the file1 and file2 have the same table names, but file1 it's from one old version and file2 from new version of the same table. I need to produce the file3 with all table_names and know if the occurence it's from old or new version of same table.
(the same table have different data depending of version and i need to resume if the table have old or new data
example:
file3
tab1 > file1
tab2 > file1
tab3 > file1
tab4 > file2
tab5 > file2
tab6 > file2
i hope it's clear explained for my poor english, and sorry if i have changed the original question!
+ thanks and regards
Francesco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:13 AM
тАО09-06-2006 10:13 AM
Re: How i can merge two text files?
Here is a perl suggestion and sample usage
$ cat x.pl
while ($file=shift @ARGV) {
open FILE, "<$file";
while (
chomp;
$tables{$_} = $file;
}
}
foreach (sort keys %tables) {
print "$_ > $tables{$_}\n";
}$ cat x
aap
noot
mies
$ cat xx
noot
mies
teun
piet
$ cat xxx
teun
vuur$ perl x.pl x xx xxx
aap > x
mies > xx
noot > xx
piet > xx
teun > xxx
vuur > xxx
$ perl x.pl xxx x xx
aap > x
mies > xx
noot > xx
piet > xx
teun > xx
vuur > xxx
Cheers,
Hein.
- Tags:
- Perl
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:41 AM
тАО09-06-2006 10:41 AM
Re: How i can merge two text files?
I tested this under FreeBSD, as I don't have access to HP-UX at the moment. HP-UX solution should be similar.
$ cat f1 && echo '====' && cat f2
tab1
tab1
tab2
tab3
tab4
====
tab2
tab4
tab6
tab7
$ grep -H '' * | sort -t: +1 | uniq
f1:tab1
f1:tab2
f2:tab2
f1:tab3
f1:tab4
f2:tab4
f2:tab6
f2:tab7
PCS
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:44 AM
тАО09-06-2006 10:44 AM
Re: How i can merge two text files?
thanks for script, but it's too hard for me.(i don├В┬┤t know use of perl) i will try to use it.
A traditionally unix script would be more easy for me.
thanks.
Best regards.
Francesco
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 10:44 AM
тАО09-06-2006 10:44 AM
Re: How i can merge two text files?
#!/usr/bin/ksh
TMP=/var/tmp/merge.$$
for i in $* ; do
awk -v NAME=$i '
{ print $0, ">", NAME
} ' $i >> $TMP
done
sort -u -k1,1 $TMP
rm -f $TMP
The output for the 3 files:
$ merge x*
aap > x
mies > x
noot > x
piet > xx
teun > xx
vuur > xxx
- Tags:
- awk
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 02:20 PM
тАО09-06-2006 02:20 PM
Re: How i can merge two text files?
$ awk '{a[$1]=FILENAME} END {for (k in a) { print k " > " a[k] }}' file1 file2
With the same sample files
$ grep "." x*
x:aap
x:noot
x:mies
xx:noot
xx:mies
xx:teun
xx:piet
xxx:teun
xxx:vuur
$ awk '{a[$1]=FILENAME} END {for (k in a) { print k " > " a[k] }}' x xx xxx
teun > xxx
vuur > xxx
mies > xx
aap > x
noot > xx
piet > xx
$ awk '{a[$1]=FILENAME} END {for (k in a) { print k " > " a[k] }}' xxx xx x
teun > xx
vuur > xxx
mies > x
aap > x
noot > x
piet > xx
Hein
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 06:21 PM
тАО09-06-2006 06:21 PM
Re: How i can merge two text files?
awk '{
if (x[$1]) {
if (FILENAME=="file2")
x[$1]=FILENAME
} else
x[$1]=FILENAME
} END{for (i in x) print i" > "x[i]}' file1 file2
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО09-06-2006 08:18 PM
тАО09-06-2006 08:18 PM
Re: How i can merge two text files?
thanks to all! with the last solution i have produced the correct file.
Best regards.
Francesco