- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Re: Script question - comm limits
Operating System - HP-UX
1753500
Members
3623
Online
108794
Solutions
Forums
Categories
Company
Local Language
back
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Forums
Discussions
back
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
Blogs
Information
Community
Resources
Community Language
Language
Forums
Blogs
Go to solution
Topic Options
- 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
02-10-2009 09:51 PM
02-10-2009 09:51 PM
Re: Script question - comm limits
I had an existing Perl script to compare lines, based on a key value first, and the whole line next, printing matching lines.
It can easily be adapted to use different key functions, or different outputs (non-matching)
Here it is, using the first sequence of numbers on a line as keys.
--------------- comm_12_numeric.pl ---------
#
# look for matching lines based on a key value
#
# Open files
#
$name = shift @ARGV or die "Must provide first filename";
open F1, "<$name" or die "Could not read file $name";
$name = shift @ARGV or die "Must provide second filename";
open F2, "<$name" or die "Could not read file $name";
my ($f1, $f2, $k1, $k2);
# Read a line from F1 into global $f1, and return its key value.
sub k1() {
$f1 =;
exit unless defined ($f1);
$f1 =~ m/^(\d+)/;
return $1;
}
# Read a line from F2 into global $f2, and return its key value.
sub k2() {
$f2 =;
exit unless defined ($f2);
$f2 =~ m/^(\d+)/;
return $1;
}
#
$k1 = &k1;
$k2 = &k2;
while ( 1 ) {
if ($k1 == $k2) {
print $f1 if ($f1 eq $f2);
$k1 = &k1;
$k2 = &k2;
} else {
if ($k1 > $k2) {
$k2 = &k2 while $k1 > $k2
} else {
$k1 = &k1 while $k2 > $k1
}
}
}
-----------------
For sake of completeness a perl equivalent for 'comm -12', printing matching lines ordered using the whole line. Note how only 2 string variables and 2 file variables are used.
---------------- comm_12_text.pl ---------
#
# Open files
#
$name = shift @ARGV or die "Must provide first filename";
open F1, "<$name" or die "Could not read file $name";
$name = shift @ARGV or die "Must provide second filename";
open F2, "<$name" or die "Could not read file $name";
my $f1 =;
my $f2 =;
while (defined ($f1) & defined ($f2)) {
if ($f1 eq $f2) {
print $f1;
$f1 =;
$f2 =;
} else {
if ($f1 gt $f2) {
$f2 = while defined ($f2) & $f1 gt $f2;
} else {
$f1 = while defined ($f1) & $f2 gt $f1;
}
}
}
----------
Cheers,
Hein.
It can easily be adapted to use different key functions, or different outputs (non-matching)
Here it is, using the first sequence of numbers on a line as keys.
--------------- comm_12_numeric.pl ---------
#
# look for matching lines based on a key value
#
# Open files
#
$name = shift @ARGV or die "Must provide first filename";
open F1, "<$name" or die "Could not read file $name";
$name = shift @ARGV or die "Must provide second filename";
open F2, "<$name" or die "Could not read file $name";
my ($f1, $f2, $k1, $k2);
# Read a line from F1 into global $f1, and return its key value.
sub k1() {
$f1 =
exit unless defined ($f1);
$f1 =~ m/^(\d+)/;
return $1;
}
# Read a line from F2 into global $f2, and return its key value.
sub k2() {
$f2 =
exit unless defined ($f2);
$f2 =~ m/^(\d+)/;
return $1;
}
#
$k1 = &k1;
$k2 = &k2;
while ( 1 ) {
if ($k1 == $k2) {
print $f1 if ($f1 eq $f2);
$k1 = &k1;
$k2 = &k2;
} else {
if ($k1 > $k2) {
$k2 = &k2 while $k1 > $k2
} else {
$k1 = &k1 while $k2 > $k1
}
}
}
-----------------
For sake of completeness a perl equivalent for 'comm -12', printing matching lines ordered using the whole line. Note how only 2 string variables and 2 file variables are used.
---------------- comm_12_text.pl ---------
#
# Open files
#
$name = shift @ARGV or die "Must provide first filename";
open F1, "<$name" or die "Could not read file $name";
$name = shift @ARGV or die "Must provide second filename";
open F2, "<$name" or die "Could not read file $name";
my $f1 =
my $f2 =
while (defined ($f1) & defined ($f2)) {
if ($f1 eq $f2) {
print $f1;
$f1 =
$f2 =
} else {
if ($f1 gt $f2) {
$f2 =
} else {
$f1 =
}
}
}
----------
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
02-11-2009 06:17 AM
02-11-2009 06:17 AM
Re: Script question - comm limits
Hello all,
The solution is to use sort with no options on your source files.
To confirm,
1- I resorted the files and it worked properly.
2- I took a subset of my original files (first 2000 lines presorted with sort -n) to test with reduced numbers; comm failed.
comm succeeded with my test data because all my test data starts with the same string.
I extracted all entries matching '211[0-9]*.doc' to reduce numbers but that made the numeric sort match the alpha sort.
Thanks all
RayB
The solution is to use sort with no options on your source files.
To confirm,
1- I resorted the files and it worked properly.
2- I took a subset of my original files (first 2000 lines presorted with sort -n) to test with reduced numbers; comm failed.
comm succeeded with my test data because all my test data starts with the same string.
I extracted all entries matching '211[0-9]*.doc' to reduce numbers but that made the numeric sort match the alpha sort.
Thanks all
RayB
- « Previous
-
- 1
- 2
- Next »
The opinions expressed above are the personal opinions of the authors, not of Hewlett Packard Enterprise. By using this site, you accept the Terms of Use and Rules of Participation.
News and Events
Support
© Copyright 2024 Hewlett Packard Enterprise Development LP