- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- Script Urgent !!
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
Forums
Discussions
Discussions
Discussions
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
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
10-03-2006 07:36 AM
10-03-2006 07:36 AM
I have two files
cat file1
host1-80 10
host2-80 15
cat file2
host1-80 30
host2-80 20
BAsically they are the number of hits to an apps server and the files are created on a daily basis. I want to print the diffrence of second column ( file2 - file1 )
i.e.,
cat result
host1-80 20
host2-80 5
Can anybody help with the simplest code. I can use Korn shell, perl, awk, sed .... anything.
Thanks in advance,
Kaps
Solved! Go to Solution.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:05 AM
10-03-2006 08:05 AM
Re: Script Urgent !!
#!/usr/contrib/bin/perl -w
my $file1 = "/tmp/foo1.txt";
my $file2 = "/tmp/foo2.txt";
open FILE, "< ".$file1 || die "Can't open file: $@";
@file1 =
close (FILE);
open FILE, "< ".$file2 || die "Can't open file: $@";
@file2 =
close (FILE);
foreach my $line1 (@file1) {
chomp($line1);
my @array1 = split(/ /, $line1);
foreach my $line2 (@file2) {
chomp($line2);
my @array2 = split(/ /, $line2);
if ($array1[0] eq $array2[0]) {
print "Difference for ".$array2[0].": ".($array2[1] - $array1[1])."\n";
}
}
}
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:06 AM
10-03-2006 08:06 AM
Re: Script Urgent !!
#!/usr/bin/ksh
host1var1=`grep "host1-80" file1|cut -d" " -f2`
host2var1=`grep "host2-80" file1|cut -d" " -f2`
host1var2=`grep "host1-80" file2|cut -d" " -f2`
host2var2=`grep "host2-80" file2|cut -d" " -f2`
host1rslt=$(($host1var2-$host1var1))
host2rslt=$(($host2var2-$host2var1))
echo "host1-80 " $host1rslt
echo "host2-80 " $host2rslt
exit
Yang
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:11 AM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:12 AM
10-03-2006 08:12 AM
Re: Script Urgent !!
SERVERS="host1-80 host2-80"
RESULT=0
for i in $SERVERS
do
RESULT=0
HITFILE1=$(cat file1 | grep $i | awk '{print $2}')
HITFILE2=$(cat file2 | grep $i | awk '{print $2}')
if [ $HITFILE1 -gt $HITFILE2 ]
then
echo $HITFILE1 $HITFILE2
RESULT=`echo $HITFILE1-$HITFILE2|bc`
else
echo $HITFILE2 $HITFILE1
RESULT=`echo $HITFILE2-$HITFILE1|bc`
fi
echo $RESULT
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:16 AM
10-03-2006 08:16 AM
Re: Script Urgent !!
#!/bin/sh
cat file1 | while read host value1
do
value2=`grep $host file2|awk '{print $2}'`
echo $host `expr $value2 - $value1`
done
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:26 AM
10-03-2006 08:26 AM
Re: Script Urgent !!
host1-80 : 20
host2-80 : 5
- read both files.
- split line into 'host name' and 'new count'
- if old count in array
--- then subtract and print
--- else stick new value into array.
Cheers,
Hein.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:30 AM
10-03-2006 08:30 AM
Re: Script Urgent !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 08:40 AM
10-03-2006 08:40 AM
Re: Script Urgent !!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 09:00 AM
10-03-2006 09:00 AM
Re: Script Urgent !!
Richard Fogle , Thanks It does work.
Yang, Thanks it works as long as the file has just 2 lines.
Jonathan Fife , I wish I could give you 20 points !! Fantastic !! Wow ! I wish I could script like that !
Jannik , Thanks .. it is again hard coded .. yet I appreciate your time spent on my request.
Hein van den Heuvel, Wow ! Perl is always perl ! Wonderfull !
Thank you very much guys ...
Regards,
Kaps
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
10-03-2006 09:03 AM
10-03-2006 09:03 AM